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

I got it correct - but when I added a second sentence, the "document.write" no longer worked - why?

Hey everyone,

I got the exercise correct using a different format compared to Dave - I tried to use his format too (using the +=), for practice - but through isolation, I've found out that my last line prevents the document.write from running. Can anyone tell me why?

(last line is

 "setence += "The people in the village then " + pastTenseVerb + " " + "him and smiled." + "</h2>";

Thanks -

"<h2>There once was a [adjective] [noun] who ate all the [plural noun] in the village. The people in the village then [past tense verb] him and smiled.</h2>"

alert("Ready to play Madlibs?");
var adjective = prompt("Please provide an adjective");
var noun = prompt("Please type a noun");
var pluralNoun = prompt("Please type a plural noun");
var pastTenseVerb = prompt("Please type a past tense verb");

var sentence = "<h2>There once was a " + adjective;

sentence += " " + noun + " " + "who ate all the ";
sentence += pluralNoun + " in the village. ";
setence += "The people in the village then " + pastTenseVerb + " " + "him and smiled." + "</h2>";
alert("All done. Ready for the message?");
document.write(sentence);

1 Answer

You have a typo.

Setence !== Sentence. :D

"setence += "The people in the village then " + pastTenseVerb + " " + "him and smiled." + "</h2>";
// to 
"sentence += "The people in the village then " + pastTenseVerb + " " + "him and smiled." + "</h2>";

Haha thank you - can't believe I missed that