rt 2Make the following variables (all of them should be OUTSIDE OF EVERY FUNCTION ON TOP OF MAIN.JS), along with the variables I left for you containing images: computerNumber, start it with -1 or any other numberdefine a function and attach it to each of your buttons (and/or to the user hitting the enter key). Call it takeTurn. This function should take a parameter. 1 for rock, 2 for paper, 3 for scissors:each button should have a function call with a different number passed in as a parameter based on how the function should expect numbersIn the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )Also put two alerts, one to show the user's number (representing which button they pushed) and one to show the computer's random numberYou are done when the alert in the function works correctly
Question
rt 2Make the following variables (all of them should be OUTSIDE OF EVERY FUNCTION ON TOP OF MAIN.JS), along with the variables I left for you containing images: computerNumber, start it with -1 or any other numberdefine a function and attach it to each of your buttons (and/or to the user hitting the enter key). Call it takeTurn. This function should take a parameter. 1 for rock, 2 for paper, 3 for scissors:each button should have a function call with a different number passed in as a parameter based on how the function should expect numbersIn the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )Also put two alerts, one to show the user's number (representing which button they pushed) and one to show the computer's random numberYou are done when the alert in the function works correctly
Solution
Sure, here's a step-by-step guide on how to implement this in JavaScript:
- Declare the variables at the top of your main.js file:
let computerNumber = -1;
- Define a function called
takeTurnthat takes a parameter:
function takeTurn(userNumber) {
// function body will go here
}
- Attach this function to each of your buttons. You can do this in the HTML file where the buttons are defined. For example, if you have a button for "rock", it might look like this:
<button onclick="takeTurn(1)">
Similar Questions
Make the following variables (all of them should be OUTSIDE OF EVERY FUNCTION ON TOP OF MAIN.JS), along with the variables I left for you containing images: num1 a random number between 0 and 9num2 a random number between 0 and 9num3 a random number between 0 and 9totalGuesses start it with a 0use randomInt()define a function and attach it to your button (and/or to the user hitting the enter key). Call it makeGuess. This function should:find what the user typed in the inputs for each number, store it in a variable called userGuessclear the inputsalert all three of the user numbers so you can see it is workingYou are done when the alert in the function works correctly
each button should have a function call with a different number passed in as a parameter based on how the function should expect numbers
Create In your HTML:a heading that says "Play Rock Paper Scissors"a paragraph underneath it with an input tag and a button in it. The paragraph should say "How many games would you like to play?" then the input, then a button that says "choose number of games"another paragraph that contains three buttons, one that says Rock, one that says paper, one that says scissorsa table with 2 rows and 3 boxes in each rowA paragraph that says "Games to play"A paragraph that says "0"Style it up nicely so it looks goodYou are done when you have all of this
make a variable outside of all functions called numGamesdefine another function called setNumberOfGames. Attach it to the button for choosing the number of games. It should find the input where the user chose their number of games, and store the number in numGamesIt should also put that number in the innerHTML of the paragraph on the bottom of the page.Go back to the takeTurn function. In it, every time the function is called, the numGames variable should go down by 1 and the new value should go in the paragraph at the bottom of the pageYou are done if the button set the number at the bottom of the page, and clicking rock, paper, or scissors, reduces that number by 1 each time.
remove the alert from part 2, you don't need it anymoremake a variable outside of all functions called numGamesdefine another function called setNumberOfGames. Attach it to the button for choosing the number of games. It should find the input where the user chose their number of games, and store the number in numGamesIt should also put that number in the innerHTML of the paragraph on the bottom of the page.Go back to the takeTurn function. In it, every time the function is called, the numGames variable should go down by 1 and the new value should go in the paragraph at the bottom of the pageYou are done if the button set the number at the bottom of the page, and clicking rock, paper, or scissors, reduces that number by 1 each time.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.