JavaScript JavaScript Basics Working With Numbers The Mad Libs Challenge Revisited

James Pawson
James Pawson
2,066 Points

Script (prompts) not executing.

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

This is my script but it's not executing anything.

3 Answers

Steven Parker
Steven Parker
177,523 Points

To preserve your program structure, use "Markdown" formatting. There's a pop-up "cheatsheet" below, or you can watch this video on code formatting.

But at first glance, it looks like you have a couple of incorrect operator symbols, for example:

questionsLeft = ' [' + questions = 'questions left]';  // original
questionsLeft = ' [' + questions + 'questions left]';  // fixed
Kristoffer A-L
Kristoffer A-L
5,863 Points

Hi James,

I think I spot the reason. If you look at lines 4 and 7, there should be a "+" instead of a "=".

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>';
console.log(sentence);

Best regards, Kris

James Pawson
James Pawson
2,066 Points

Thanks for the answers! ItNs asking me to pick a best answer, although they re both equally as good!