Question
Project Outcomes: Write a JavaScript program that uses: Variables to hold user-provided values Functions to gather data from the user and compute data Prep Readings:
Project Outcomes:
Write a JavaScript program that uses:
Variables to hold user-provided values
Functions to gather data from the user and compute data
Prep Readings:
JavaScript and jQuery, Chapters 1 through 3.
Project Requirements:
Write a program that generates mad libs based on input from the user. The program will ask the user for their first name and then use that name to greet the user. It will then prompt the user for at least four different types of words and generate a mad lib sentence or paragraph based on the user's input.
The program should use a function to get the user's first name. It will then output a greeting to the user directly from the function. (See the example below.)
You are required to use a function to gather the words from the user used to fill in the blanks of the mad lib. Write a function that takes in a string representing the category of the word (ex: "noun", "adjective", etc.). The function should then use a prompt() to ask the user to input a word of that type. The function should then return what the user entered. For example, if you pass in the string "noun" to the function, the function should ask the user "Please enter a noun." and return the string that they entered.
Generate a mad-lib by calling the function multiple times and storing the returned words in variables. You can stitch together the variables along with string values to make a mad lib. See this website for an example of some Mad Libs that you can use. Feel free to be creative: http://www.redkid.net/madlibs/
Example:
Prompt: "Welcome to the Mad Lib program. What's your name?"
Input "Bill"
Alert: "Pleased to meet you, Bill! Let's get started."
Prompt: "Please enter an exclamation:"
Input: "ouch"
Prompt: "Please enter an adverb:"
Input: "stupidly"
Prompt: "Please enter a noun:"
Input: "cat"
Prompt: "Please enter an adjective:"
Input: "brave"
Alert: Here's your madlib! "ouch! he said stupidly as he jumped into his convertible cat and drove off with his brave wife."
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started