<html>
<head>
  <title>Play Now! Simple Random Number Game in HTML</title>
  <style>
    body {
      background-color: #f2f2f2;
    }
<pre><code>.box {
  background-color: #d0d0d0;
  width: 200px;
  height: 200px;
  border-radius: 10px;
  margin-left: auto;
  margin-right: auto;
  margin-top: 50px;
  text-align: center;
  font-family: Arial, sans-serif;
}

.box p {
  font-size: 30px;
}
</code></pre>
  </style>
</head>
<body>
  <div class='box'>
    <p id='randomNumber'>Click to play!</p>
  </div>
  <script>
    // Generate a random number between 1 and 10
    function getRandomNumber() {
      return Math.floor(Math.random() * 10) + 1;
    }

    // On click, generate a new random number
    document.querySelector('.box').addEventListener('click', function() {
      let randomNumber = getRandomNumber();
      document.getElementById('randomNumber').innerHTML = randomNumber;
    });
  </script>
</body>
</html>
Play Now! Simple Random Number Game in HTML

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

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