<html>
<head>
<title>Guess The Number Game</title>
</head>
<body>
<h1>Guess The Number Game</h1>
<p>I'm thinking of a number between 1 and 10. Can you guess it?</p>
<input type="text" id="guessField" />
<button onclick="checkGuess()">Guess</button>
<script>
    let randomNumber = Math.floor(Math.random() * 10) + 1;

function checkGuess() {
  let userGuess = document.getElementById('guessField').value;
  if (userGuess == randomNumber) {
    alert('Congratulations! You guessed the right number!');
  } else {
    alert('Sorry, that's not correct. Try again!');
  }
}
</script>
</body>
</html>
Simple HTML Guessing Game: How to Build It

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

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