<html>
<head>
  <title>Guess the Number Game</title>
  <script>
    // Generate a random number
    var randomNumber = Math.floor(Math.random() * 10 + 1);
    // Guess the number
    var guess = prompt('Guess a number between 1 and 10');
    // Check if the guess is correct
    if(parseInt(guess) === randomNumber) {
        alert('You guessed the number!');
    }
    else {
        alert('Sorry, the number was ' + randomNumber);
    }
  </script>
</head>
<body>
  <h1>Guess the Number Game</h1>
  <p>
    Try to guess the correct number between 1 and 10.
  </p>
</body>
</html>
Simple HTML Guessing Game: How to Create a Basic Number Guessing Game

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

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