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

Jon Speake
Jon Speake
3,466 Points

Is there a need for var sentence? my code worked fine without, seems like an extra step thats unnecessary?

Here's my code which worked fine without combining the 'var sentence' parts.

var player = prompt("What's your name?");
alert(player + ", We are going to have some fun, please answer these next few questions.");
var person = prompt('Pick the name of someone you know');
var colour = prompt('Pick a colour');
var bodyPart = prompt('Pick a body part');
var smell = prompt('Choose a yucky smell');
alert("OK " + player + ", you are done! Get ready for your story.");
document.write('<h2>Once upon a time, ' + person + ' had a ' + colour + ' ' + bodyPart + ' and it smelled of ' + smell + '.</h2>');

1 Answer

Steven Parker
Steven Parker
231,269 Points

There's no functional difference.

Constructing the sentence in pieces as shown in the video makes the program a little bit easier to read, and therefore an advantage for teaching. But the output is exactly the same.