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 trialNayoon kim
3,098 PointsI Would like to know why I have to repeat defining the 'questionsLeft' here to work // questions -= 1; //
// Here are my codes and I have TWO questions
var questions = 3; var questionsLeft = ' [There are '+ questions + ' questions left ]'; var adjective = prompt('Please type an adjective'+ questionsLeft);
questions -= 1 ;
questionsLeft =' [There are '+ questions + ' questions left ]';
//** I feel like there is no need for me to define here as it is already done up there. but it //didn't work without this sentence and I wonder why.
var verb = prompt('Please type a verb'+ questionsLeft );
questions -= 1; questionsLeft =' [There are '+ questions + ' questions left ]'; var noun = prompt('Please type a noun'+ questionsLeft);
if (questions=1) { alert('All done. Ready for the message?'); // * *Also I have put --- break; ---- here and it didn't work and I don't know why I cant put it here *// }
var sentence = "<h2>There once was a " + adjective; sentence += ' programmer who wanted to use JavaScript to ' + verb; sentence += ' the ' + noun + '.</h2>'; document.write(sentence);
1 Answer
Steven Parker
231,269 PointsIt's necessary to reassign questionsLeft whenever questions changes for it to reflect the current value.
But you could eliminate that variable entirely by extending the prompt argument like this:
var verb = prompt('Please type a verb [There are ' + questions + ' questions left]');
Nayoon kim
3,098 PointsNayoon kim
3,098 Pointsahhh you helped me with all the questions that I had today ! thanks a lot and your willpower and persistence to learn how to code inspired me as well ! thank you