Using built-in objects Math.random Realize Guessing Number Game

Time:2021-3-2

function getRandom(min,max){

return Math.floor ( Math.random () * (max min + 1)) + min; / / get the random integer between two numbers, including the two values penetrated by the real parameter.

}

var random = getRandom(1,10);  

For (VaR I = 1; I < = 10; I + +) {/ / for loop traversal, declaring the variable from the first time to the 10th time of pop-up input opportunity.

Var guessnum = prompt (‘Please enter the number to guess’);

if (guessNum>random){

Alert (“you guessed big”);

}else if(guessNum

Alert (‘You guess it’s too small ‘);

}else{

Alert (“you guessed right”);

  break;

}

if(i==10){

Alert (“your 10 opportunities have been used up”);

}

}