Simple HTML Number Guessing Game

Guess the Number

I'm thinking of a number between 1 and 10. Try to guess it!

<script>
  //Generate a random number between 1 and 10
  var randomNumber = Math.floor(Math.random() * 10) + 1;

  //Get the guess from the user
  var guess = prompt('Guess a number between 1 and 10');

  //Check the guess
  if (parseInt(guess) === randomNumber) {
    alert('You guessed the number ' + randomNumber + '! You win!');
  } else {
    alert('Sorry, the number was ' + randomNumber + '. You lose!');
  }
</script>
Simple HTML Number Guessing Game - Play Now!

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

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