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 trialKatie Shook
12,326 PointsQuestions left isn't going down
Can anyone help me figure out where my error is? Thanks! https://w.trhou.se/orf47o4esa
2 Answers
benyoungblood
10,062 PointsHi Katie,
So the issue you are running into has to do with the order of your variables. So your questionsLeft
variable is assigned once at the top but then is never re-assigned with the new decremented questions
variable. If you see below I have re-assigned your questionsLeft
variable with the new questions
value each time which gives you the output you want. I also removed the code you had on line 2 which just appeared to be a random string not assigned to anything. I hope this helps.
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;
var questionsLeft =" ["+ questions + " questions left]";
var noun = prompt('Please type a noun' + questionsLeft);
questions -= 1;
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);
Katie Shook
12,326 PointsThanks so much!