each button should have a function call with a different number passed in as a parameter based on how the function should expect numbers
Question
each button should have a function call with a different number passed in as a parameter based on how the function should expect numbers
Solution
It seems like you're asking how to assign a different function call to each button, with each function call having a unique number passed in as a parameter. Here's a step-by-step guide on how to do this in JavaScript:
- First, define your function. This function should be designed to accept a number as a parameter. For example:
function myFunction(num) {
console.log("Button number " + num + " was clicked.");
}
- Next, create your buttons in HTML. Give each button a unique ID so you can reference them in your JavaScript code:
<button id="button1">Button 1</button>
<button id="button2">Button 2</button>
<button id="button
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: 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
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.
Create a class FooBar, whose objects have foo and bar as their attributes.Also, write the function solve(obj, param1, param2).obj: Object of class FooBarparam1, param2: some random numbers provided to you directly as input.See the example for more clarity.InputInput will have 4 numbers, viz. foo,bar,param1, param2 separated by spaces.You need not worry about the same, it is handled properly by the hidden pre-function code.Example:4 5 6 7OutputFunction solve(obj, param1, param2) should return the value obj.foo + obj.bar + func(param1, param2)There is a global function named func(a, b), which takes two numbers as parameters, and its implementation is hidden.Note: func uses properties of obj (using this, just like class methods), but does not accept obj as a parameter.
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.