<html>
<head>
  <title>Simple Number Guessing Game</title>
</head>
<body>
  <h3>Simple Number Guessing Game</h3>
  <p>Guess a number between 1 and 10 and click the button below to see if you're right!</p>
  <form action="">
    <input type="number" name="guess" min="1" max="10" />
    <button type="submit">Guess</button>
  </form>
  <script>
    const guess = document.querySelector("input[name='guess']").value;
    const numberToGuess = 5;
    if (guess == numberToGuess) {
      alert('You guessed correctly!');
    } else {
      alert('Sorry, wrong guess!');
    }
  </script>
</body>
</html>
<p>How to Play:</p>
<ol>
<li>Enter a number between 1 and 10 in the input box.</li>
<li>Click the 'Guess' button.</li>
<li>If you guess the correct number (in this case 5), you will see an alert saying 'You guessed correctly!'</li>
<li>If you guess the wrong number, you will see an alert saying 'Sorry, wrong guess!'</li>
</ol>
Simple Number Guessing Game: Play Now!

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

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