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