JavaScript JavaScript Basics Working With Numbers The Mad Libs Challenge Revisited

The Mad Libs Challenge

i dont know how to do it with the loop version did anyone did it ?

3 Answers

Steven Parker
Steven Parker
177,579 Points

You aren't expected to be able to do that yet.

At the end of the video, he says, "you'll learn about loops in another course on Treehouse."

Leonardo Motta
Leonardo Motta
11,284 Points
console.log('Start program');

var questions = 3;
while (questions != 0) {
  if (questions == 3) {
    var questionsLeft = ' [' + questions + ' questions left]';
    var userAdjective = prompt('Please type an adjective' + questionsLeft);
  } else if (questions == 2) {
    questionsLeft = ' [' + questions + ' questions left]';
    var userVerb = prompt('Please type a verb' + questionsLeft);
  } else if (questions == 1) {
    questionsLeft = ' [' + questions + ' questions left]';
    var userNoun = prompt('Please type a noun' + questionsLeft);
  }
  questions--;
}
alert('All done, ready?');
document.write('<p>Once upon a time a ' + userAdjective + ' programmer tried to use JavaScript to ' + userVerb + ' the ' + userNoun + '</p>');

/*This log was to check how the variable is kept depending on the user answer, like if he clicks cancel or an empty answer, just wanted to see how everything is stored*/
console.log('adjective: ' + userAdjective + ' verb: ' + userVerb + ' noun: ' + userNoun);

console.log('End program');

thanks a lot :)