n the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )
Question
n the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )
Solution
Here is how you can reassign computerNumber to a random number between 1 and 3 using randomInt() function. I'm assuming that you're using JavaScript.
// First, you need to define the function randomInt() if it's not already defined.
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// Then, you can reassign computerNumber to a random number between 1 and 3.
let computerNumber = randomInt(1, 3);
In this code, randomInt() function generates a random integer between the two numbers provided as arguments. Then, computerNumber is reassigned to a random number between 1 and 3 by calling this function with 1 and 3 as arguments.
Similar Questions
On Python line 5, use random.randint() to generate a number between 0 and 2, and store the result to a variable named randomNumber.
Examine the following code block.The code has either a syntax or logic error in one line only.Identify the problem line then write it out correctly in the box provided.Your answer must be exact, including correct spelling and spacing.void getRandNum(int low, int high) { // return a value from within the range given int myNum = 0; myNum = rand() % high + low; return myNum;}
var MovesCount=0function randomPos(){ var arr = []; while(arr.length < 9){ var r = ((Math.floor(Math.random() * 3)+1).toString())+((Math.floor(Math.random() * 3)+1).toString()); if(arr.indexOf(r) === -1) arr.push(r); } return arr}var RandomPos=randomPos()for(let i =0;i<document.getElementsByClassName("tile").length;i++){ document.getElementsByClassName("tile")[i].style.gridArea=RandomPos[i][0]+"/"+RandomPos[i][1]}function MoveMe(tile){ var EmptyTile=document.querySelector(".emtile") var Possibilties=[ parseInt(RandomPos[tile][0])+1==parseInt(RandomPos[8][0])&&parseInt(RandomPos[tile][1])==parseInt(RandomPos[8][1]), parseInt(RandomPos[tile][0])-1==parseInt(RandomPos[8][0])&&parseInt(RandomPos[tile][1])==parseInt(RandomPos[8][1]), parseInt(RandomPos[tile][1])+1==parseInt(RandomPos[8][1])&&parseInt(RandomPos[tile][0])==parseInt(RandomPos[8][0]), parseInt(RandomPos[tile][1])-1==parseInt(RandomPos[8][1])&&parseInt(RandomPos[tile][0])==parseInt(RandomPos[8][0]), ]if(Possibilties[0]||Possibilties[1]||Possibilties[2]||Possibilties[3]){ MovesCount++; EmptyTile.style.gridArea=RandomPos[tile][0]+"/"+RandomPos[tile][1]; document.querySelectorAll(".tile")[tile].style.gridArea=RandomPos[8][0]+"/"+RandomPos[8][1]; var CurrentTile=RandomPos[tile] RandomPos[tile]=RandomPos[8] RandomPos[8]=CurrentTile; NeededPos=["11","12","13","21","22","23","31","32","33"] if(RandomPos.join(".")==NeededPos.join(".")){ console.log("Game Beated"); document.querySelector(".blscreen").style.display='flex' document.querySelector(".MovesCount").innerHTML=MovesCount; var stars=0; if(MovesCount<100){ stars=3 }else if(MovesCount<200){ stars=2 }else if(MovesCount<300){ stars=1 }else{ stars=0 } for(let i=0;i<2;i++){ document.getElementsByTagName("path").style.fill="yellow" } }}}
Which of the following options is the best for generating random integer 0 or 1?
Which of these method return a pseudorandom number?Optionsrandom()rand()randomNumber()randGenerator()
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.