Simple HTML Number Guessing Game

Guess the Number

<h2>Instructions</h2>

<p>Guess the number between 1 and 10 to win the game.</p>

<script>
    let correctNumber = Math.floor(Math.random() * 10) + 1;
    let guess;
    let guesses = 0;

    // prompt the user for a number
    while (guess !== correctNumber) {
        guess = prompt('Guess a number between 1 and 10');
        guesses++;
    }

    // user guessed correctly
    alert('You guessed the correct number! It took you ' + guesses + ' guesses.');
</script>

原文地址: https://www.cveoy.top/t/topic/lmlq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录