<html>
<head>
    <title>Guess the Number</title>
    <style>
        body {
            text-align: center;
        }
        #game {
            margin: 0 auto;
            padding: 10px;
        }
    </style>
</head>
<body>
    <h1>Guess the Number</h1>
    <p>I'm thinking of a number between 1 and 10. Can you guess it?</p>
<pre><code>&lt;div id=&quot;game&quot;&gt;
    &lt;input type=&quot;number&quot; id=&quot;guess&quot; min=&quot;1&quot; max=&quot;10&quot;&gt;
    &lt;button id=&quot;submit&quot;&gt;Submit&lt;/button&gt;
    &lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;script&gt;
    let randomNumber = Math.floor(Math.random() * 10) + 1;

    document.getElementById('submit').addEventListener('click', function() {
        let guess = document.getElementById('guess').value;
        if (guess == randomNumber) {
            document.getElementById('result').innerHTML = 'You guessed the correct number!';
        } else {
            document.getElementById('result').innerHTML = 'Sorry, that was the wrong number.';
        }
    });
&lt;/script&gt;
</code></pre>
</body>
</html>
Simple HTML Number Guessing Game - Play Now!

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

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