Simple HTML Number Guessing Game - Play Now!
<html>
<body>
<h1>Guess the Number Game</h1>
<script>
var correctNumber = Math.floor(Math.random() * 10);
var guess;
var guessCount = 0;
var correctGuess = false;
<pre><code> while (guessCount < 5) {
guess = prompt('Guess a number between 0 and 10');
guessCount++;
if (parseInt(guess) === correctNumber) {
correctGuess = true;
break;
}
}
if (correctGuess) {
document.write('<h2>You guessed the number!</h2>');
} else {
document.write('<h2>Sorry. The correct number was ' + correctNumber + '</h2>');
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmfA 著作权归作者所有。请勿转载和采集!