Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.