Simple HTML Number Guessing Game - Play Now!
Guess the Number
<p>I'm thinking of a number between 1 and 10. Can you guess it?</p>
<input type="text" id="userGuess" placeholder="Type your guess here">
<button onclick="checkGuess()">Guess</button>
<div id="result">
</div>
<script>
let answer = Math.floor(Math.random() * 10) + 1;
function checkGuess() {
let userGuess = document.getElementById("userGuess").value;
let result = document.getElementById("result");
if (userGuess == answer) {
result.innerHTML = "You guessed it!";
}
else {
result.innerHTML = "Nope, that's not it.";
}
}
</script>
原文地址: https://www.cveoy.top/t/topic/lmlx 著作权归作者所有。请勿转载和采集!