JavaScript JavaScript Basics Working With Numbers The Mad Libs Challenge Revisited

2 Answers

benyoungblood
benyoungblood
6,656 Points

Hi 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);