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) Working With Numbers The Mad Libs Challenge Revisited

fredyrosales
fredyrosales
10,572 Points

My code is bugged i think?

Ok so i've been trying to figure this out but i am having no luck. When i try to preview my workspace the prompt does show up but all that comes up is the Adjective and Verb. the noun doesn't even make it. also it doesn't show how many questions i have left. heres my snapshot https://w.trhou.se/caauwv4moc thank you if you figure it out!

1 Answer

Erik Nuber
Erik Nuber
20,629 Points
var questions = 3;
var questionsLeft = '[' + questions +' questions left]';
var adjective = prompt('Please type an adjective' + questionsLeft);
questions -=1;
questionsLeft = '[' + questions +' questions left]';
var verb = prompt('Please type a verb' + questionsLeft );
questions -= 1;
questionsLeft = '[' + questions +' questions left]';
var noun = prompt('Please type a noun' + questionsLeft);
alert('All done. Ready for the message?');
var sentence = "<h2>There once was a " + adjective;
sentence += ' programmer who wanted to use JavaScript to ' + verb;
sentence += ' the ' + noun + '.</h2>';
document.write(sentence);

You are going to have to test it in something not chrome. For some odd reason document.write is not working currently.

The issue was with the lines questionsLeft. You were missing some of the concatanation.

fredyrosales
fredyrosales
10,572 Points

Thanks! I thought something like that was up. Saved me lots of time man.