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 trial

JavaScript JavaScript Basics (Retired) 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
231,236 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 :)