<html>
<head>
    <title>Guess the Number</title>
    <script>
        let secretNumber = Math.floor(Math.random() * 10) + 1;
<pre><code>    function guessNumber() {
        let guessedNumber = document.getElementById('guessedNumber').value;
        if(guessedNumber == secretNumber) {
            alert('You guessed the number correctly!');
        } else {
            alert('You guessed the wrong number!');
        }
    }
&lt;/script&gt;
</code></pre>
</head>
<body>
    <h1>Guess the Number</h1>
    <p>I'm thinking of a number between 1 and 10. Can you guess it?</p>
    <input type="number" id="guessedNumber">
    <button type="button" onclick="guessNumber()">Guess</button>
</body>
</html>
Simple HTML Guessing Game - Learn to Code

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

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