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

Sufian Javed
seal-mask
.a{fill-rule:evenodd;}techdegree
Sufian Javed
Front End Web Development Techdegree Student 790 Points

My question counter will no go down.

I've gone through my code numerous times but I cant seem to figure out what the problem may be. When I preview the page, it shows me '3 questions left' for all the questions. Anyone else have this problem?

var questions = 3; var questionsLeft = ' [' + questions + ' questions left]'; var adjective = prompt('Please type an adjective' + questionsLeft); questions -= 1; questions = ' [' + questions + ' questions left]'; var verb = prompt('Please type a verb' + questionsLeft); questions -= 1; questions = ' [' + 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);

2 Answers

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

You're updating the value of the variable "questions" with the string in place of modifying questionsLeft.

Oscar Rivas
PLUS
Oscar Rivas
Courses Plus Student 2,020 Points

You need to update questionsLeft also, because questionsLeft is composed of strings and number.

var questionsLeft = '[ ' + questions + ' left ]'; var adjective = prompt('Please type an adjective' + questionsLeft);

questions -= 1; questionsLeft = '[ ' + questions + ' left ]'; var verb = prompt('Please type a verb' + questionsLeft);

questions -= 1; questionsLeft = '[ ' + questions + ' left ]'; var noun = prompt('Please type a noun' + questionsLeft);