Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge Solution

Would that be correct too?

 var greeting = prompt("Type a Greeting");
var personName = prompt("Type a Person Name");
var dogName = prompt("Type a Dog's Name");
alert("You are Done!");
document.write("<h2>The Fox said " + greeting + "  to " + personName + " and " + dogName + "</h2>");

Yes, that works perfectly fine as well. I believe the way he did it just made it easier to read/change in the future.

You can also use Javascript Embedded Expressions to use your variable directly in a string like below:

/* Receive user input */
var noun = prompt("Input a noun:");
var adj = prompt("Input an adjective:");
var verb = prompt("Input a verb");

/* Alert the user that they are done */
alert('Input has been received. Your story is being crafted.');

/* Create sentence from the pieces. */
var story = `A young boy sold his ${adj} ${noun} to ${verb} a dog, but when he made it to the store they were all out.`; 
document.write(story);