我希望用户猜测一个随机数,但每次刷新页面时都会生成一个新的随机数
I want the user to guess a random number but every time I refresh the page a new random number generates
我需要创建一个用户必须猜测的随机数。当我刷新页面时,它似乎生成了一个新的随机数。
var userPrompt = prompt("Guess a number");
var ran = Math.floor(Math.random() * 10);
function ranNumGame(ran) {
if (userPrompt == ran) {
return "Congrats";
}
else if (ran < userPrompt) {
return "Lower";
}
else if (ran > userPrompt) {
return "Higher";
}
}
console.log(ranNumGame(ran));
var randomNumber = Math.floor(Math.random() * 10);
var userInput = prompt("Pick a number between 0 and 10");
while (userInput != randomNumber) {
alert("nope");
if (userInput < randomNumber) {
userInput = prompt("guess higher");
} else if (userInput > randomNumber) {
userInput = prompt("guess lower");
} else if (userInput == randomNumber) {
alert("congrats");
console.log("congrats");
}
}
我需要创建一个用户必须猜测的随机数。当我刷新页面时,它似乎生成了一个新的随机数。
var userPrompt = prompt("Guess a number");
var ran = Math.floor(Math.random() * 10);
function ranNumGame(ran) {
if (userPrompt == ran) {
return "Congrats";
}
else if (ran < userPrompt) {
return "Lower";
}
else if (ran > userPrompt) {
return "Higher";
}
}
console.log(ranNumGame(ran));
var randomNumber = Math.floor(Math.random() * 10);
var userInput = prompt("Pick a number between 0 and 10");
while (userInput != randomNumber) {
alert("nope");
if (userInput < randomNumber) {
userInput = prompt("guess higher");
} else if (userInput > randomNumber) {
userInput = prompt("guess lower");
} else if (userInput == randomNumber) {
alert("congrats");
console.log("congrats");
}
}