我目前正在用 Javascript 编写一个简单的程序。我不知道为什么程序不能正常工作。用户应该能够猜出一个数字,程序会告诉用户它需要猜高还是低。现在,它甚至没有给我第一个提示。谢谢大家的帮助。
<html>
<head>
</head>
<body>
<script>
//Guessing Game
function guessingGame() {
var userNumber = prompt("Pick a number 1 through 1000!", "Type your number here");
var computerNumber = Math.floor(Math.random() * 1000 + 1);
var tries = 0;
var done = false;
while (done === false) {
if (userNumber < computerNumber) {
document.write("Your number was too low.");
tries = tries + 1;
userNumber = prompt("Please guess again", "Type your number here");
} else if (userNumber > computerNumber) {
document.write("Your number was too high.");
tries = tries + 1;
userNumber = prompt("Please guess again", "Type your number here");
} else {
document.write("Great Job!!! You guessed the number in " + tries + " tries!" );
done = true;
}
}
}
guessingGame();
</script>
</body>
</html>