Simple HTML Number Guessing Game - Play Now!
<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><div id="game">
<input type="number" id="guess" min="1" max="10">
<button id="submit">Submit</button>
<p id="result"></p>
</div>
<script>
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.';
}
});
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmlw 著作权归作者所有。请勿转载和采集!