<html>
<head>
  <title>Simple Guessing Game</title>
  <style>
   body {
      text-align: center;
    }
    p {
     font-weight: bold;
   }
  </style>
</head>
<body>
  <h1>Guess the Number</h1>
  <p>I'm thinking of a number between 1 and 10. Can you guess it?</p>
  <input type="text" id="guess" />
  <button onclick="checkGuess()">Guess</button>
  <div id="message"></div>
  <script>
    var answer = Math.floor(Math.random() * 10) + 1;
    function checkGuess() {
      var guess = document.getElementById("guess").value;
      if (guess == answer) {
        document.getElementById("message").innerHTML = "You got it right!";
      } else {
        document.getElementById("message").innerHTML = "Wrong! Try again.";
      }
    }
  </script>
</body>
</html>
Simple HTML Guessing Game - Play Now!

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

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