Task
Your client would like a computer generated Madlib game.
Madlibs ask the user for a series of words which is later fitted in to a story.
This is the story of firstname secondname They were learning adjective with Station House Media Unit. Studying adjective is really verb thought firstname. Little did firstname know, but they would still be studying adjective for the next number years!
First name
Second name
Adjective (describing word)
Verb (doing word)
Number
Tip: We can use the ‘backtick’ method to output our story!
Solution
Welcome to the Madlibs Generator
A story using your own words and phrases is about to begin!
story output here


Show Code
Code
| window.onload = function() { | |
| // Get user input | |
| var firstName = prompt(“Please enter the first name of the main character”); | |
| var lastName = prompt(“Please enter the last name of the main character”); | |
| var adjective = prompt(“Please enter an adjective (descriptive word)”); | |
| var verb = prompt(“Please enter a verb (doing word)”); | |
| var number = parseFloat( prompt(“Please enter a number? “) ); | |
| let theStory =`This is the story of ${firstName} ${lastName}, | |
| They were learning ${adjective} with Station House Media Unit. | |
| Studying ${adjective} is really ${verb} thought ${firstName}. | |
| Little did ${firstName} know, but they would still be studying ${adjective} for the next ${number} years! | |
| `; | |
| //display user input | |
| document.getElementById(“madlibs-story”).innerHTML = theStory; | |
| } |
