Guess the Number Game - HTML, JavaScript
<html>
<head>
<title>Guess the Number</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 type="button" onclick="checkGuess()">Check Guess</button>
<p id="message"></p>
<script>
var correctNumber = 7;
function checkGuess(){
var userGuess = Number(document.getElementById('guess').value);
if(userGuess === correctNumber){
document.getElementById('message').innerHTML = 'You guessed correctly!';
} else {
document.getElementById('message').innerHTML = 'Sorry, that's not the correct number.';
}
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmbe 著作权归作者所有。请勿转载和采集!