Guess the Number HTML Game: Simple & Fun!
<html>
<head>
<title>Guess the Number HTML Game</title>
</head>
<body>
<h1>Guess the Number Game</h1>
<div>
<p>I'm thinking of a number between 1 and 10. Can you guess what it is?</p>
<input type="text" id="guess">
<button type="button" onclick="checkGuess()">Guess</button>
</div>
<script>
let correctNumber = 7;
function checkGuess() {
let guessedNumber = document.getElementById('guess').value;
if(guessedNumber == correctNumber) {
alert('You guessed it! The number was ' + correctNumber);
} else {
alert('Sorry, that's not it. Try again!');
}
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lnQM 著作权归作者所有。请勿转载和采集!