Simple HTML Number Guessing Game - Play Now!
<!DOCTYPE html>
<html>
<head>
<title>Simple HTML Number Guessing Game</title>
</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="text" id="guess" />
<button onclick="checkGuess()">Check My Guess</button>
<p id="result"></p>
<script>
let answer = Math.floor(Math.random() * 10) + 1;
function checkGuess() {
let guess = document.getElementById('guess').value;
let result = document.getElementById('result');
if(guess == answer) {
result.innerHTML = 'You guessed it!';
} else {
result.innerHTML = 'Sorry, that's not right. Try again!';
}
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmpj 著作权归作者所有。请勿转载和采集!