<html> 
<head> 
   <title>Random Game</title> 
</head> 
<body> 
   <h1>Random Game</h1> 
   <p> 
      Welcome to the random game! 
   </p> 
   <button onclick='startGame()'>Start Game</button> 
   <script> 
      //This function will generate a random number between 1 and 10 
      function getRandomNumber() { 
         return Math.floor(Math.random() * 10 + 1); 
      } 
<pre><code>  //This function will start the game 
  function startGame(){ 
     let randomNumber = getRandomNumber(); 
     let userInput = prompt('Guess a number between 1 and 10'); 
     if (parseInt(userInput) === randomNumber){ 
        alert('You guessed correctly! You win!'); 
     } else { 
        alert('Sorry, that wasn't the right number. You lose!'); 
     } 
  } 
</code></pre>
   </script> 
</body> 
</html>
Play a Fun Number Guessing Game Online - HTML Game

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

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