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

How about this?

var adjective = prompt("Please type an adjective");
var verb = prompt("Please type a verb");
var noun = prompt("Please type a noun");
alert ("All done. Ready for the story?");
document.write("<h2>There was an "
+ adjective + " "
+ noun
+ " who wanted to use JavaScript to "
+ verb + " the world.</h2>");

How about this? Can anything be improved?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I would say that it looks pretty solid. The only thing that somewhat bothers me (and this is really nit-picking) is the amount of concatenation that's going on here. It just inevitably makes things hard to read when the string is a bit longer. There is a way to improve this so it's a bit more readable, but you likely haven't learned it yet. That being said, Treehouse does have a 9 minute workshop on just this thing: JavaScript Template Literals.

You have this currently:

document.write("<h2>There was an "
+ adjective + " "
+ noun
+ " who wanted to use JavaScript to "
+ verb + " the world.</h2>");

But you could have:

document.write(`<h2>There was an ${adjective} ${noun} who wanted to use JavaScript to ${verb} the world.</h2>`);

I highly recommend taking a look at that workshop if you have 10 minutes extra. Those 10 minutes will save you at least that much time with concatenation headaches and escaping characters down the road.

You're doing great! :sparkles:

Hi Jennifer,

Thank you for the answer. I will definitely check it out.