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.
Question
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.
Solution
This seems to be a set of instructions for coding in JavaScript. Here's how you can implement it:
- Declare a variable outside of all functions:
let numGames;
- Define a function called
setNumberOfGamesand attach it to the button for choosing the number of games. This function should get the user's input for the number of games, store it innumGames, and also display it in a paragraph at the bottom of the page:
function setNumberOfGames() {
numGames = document.getElementById('inputId').value; // replace 'inputId' with the actual id of your input field
document.getElementById('paragraphId').innerHTML = numGames; // replace 'paragraphId' with the actual id of your paragraph
}
document.getElementById('buttonId').addEventListener('click', setNumberOfGames); // replace 'buttonId' with the actual id of your button
- Modify the
takeTurnfunction so that it decreasesnumGamesby 1 every time it's called, and updates the paragraph at the bottom of the page:
function takeTurn() {
numGames--;
document.getElementById('paragraphId').innerHTML = numGames;
// rest of your function
}
Now, when you click the button, it should set the number at the bottom of the page, and clicking rock, paper, or scissors should reduce that number by 1 each time.
Similar Questions
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.
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.
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 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
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
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.