Question

In: Computer Science

Java Script Computer science Mad Libs Program - Mad Libs is a paper and pencil game...


Java Script
Computer science
Mad Libs Program -

Mad Libs is a paper and pencil game where a leader asks a group for specific words (nouns, verbs, adverbs, adjectives, names, numbers) that are then replaced in a story. The group does not know what the story is so the replaced words usually make the story funny.

You will write a Java Script program that:
* Informs the user what the program does using an alert
* Asks the user for eight words (two nouns, two verbs, three adjectives, and one adverb) using prompts
* Replace an existing story that you have already written with the words given to you by the user
* Show the new story
You will need to create a short story (three or four sentences) that contains the types of words you are asking the user to give you. You will be able to display the new story using document.write

You code needs all of the HTML required code and a comment. Save this file to your shared class folder, making sure you name it correctly using the class file naming convention.

Solutions

Expert Solution

****This requires some effort so please drop a like if you are satisfied with the solution****

index.html:

<html>

    <head>

        <script src="index.js"></script>

    </head>

    <body>

        <button onclick="replace()">Click me</button>

    </body>

</html>

index.js

var str="I am a good person He is very bad my name is Mark and his name is Albert he is doing great but feeling bad very rarely 100% fully"

words=[]

document.write(str);

function replace(){

words.push(window.prompt("Enter a adjective"))

words.push(window.prompt("Enter a adjective"))

words.push(window.prompt("Enter a verb"))

words.push(window.prompt("Enter a verb"))

words.push(window.prompt("Enter a adverb"))

words.push(window.prompt("Enter a adverb"))

words.push(window.prompt("Enter a name"))

words.push(window.prompt("Enter a name"))

words.push(window.prompt("Enter a number"))

story=str.split(" ");

for(i=0;i<story.length;i++){

    if(story[i]=="good")

        story[i]=words[0];

    if(story[i]=="bad")

        story[i]=words[1]

    if(story[i]=="doing")

        story[i]=words[2]

    if(story[i]=="feeling")

        story[i]=words[3]

    if(story[i]=="rarely")

        story[i]=words[4]

    if(story[i]=="fully")

        story[i]=words[5]

    if(story[i]=="Mark")

        story[i]=words[6]

    if(story[i]=="Albert")

        story[i]=words[7]

    if(story[i]=="100%")

        story[i]=words[8]   

}

story=story.join(" ");

console.log(story);

var newStory=story;

str=""

document.write(newStory);

}



Related Solutions

Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
How is computer arithmetic distinct from pencil-and-paper forms?
How is computer arithmetic distinct from pencil-and-paper forms?
write a python script for rock scissors paper game
write a python script for rock scissors paper game
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to...
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to look up Random numbers in Java. First ask the user what language they want to play in. Choice 1 is English, but choice 2 can be whatever real language you want. Your first loop is making sure they enter good input. If there is a tie you don't give them the option to play again. They have to. Outer loop runs until they say...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Your program must prompt the player 1 and player 2 to each enter a string for their choice: rock, paper, or scissors. Then appropriately reports if “Player 1 wins”, “Player 2 wins”, or “It...
java script coding to create a math test program with 5 questions.
java script coding to create a math test program with 5 questions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT