Simple HTML Guessing Game - Play Now!
<html>
<head>
<title>Guess the Number</title>
<script type="text/javascript">
// set the number you want the user to guess
var numberToGuess = 5;
<p>// function that is called when the user clicks the 'Guess' button
function submitGuess() {
// get the number the user guessed
var userGuess = document.getElementById('guess').value;</p>
<p>// check if the user's guess is correct
if (userGuess == numberToGuess) {
alert('You guessed it! The number was ' + numberToGuess);
}
else {
alert('Sorry, wrong number. Guess again!');
}
}
</script></p>
</head>
<body>
<h1>Guess the Number</h1>
<p>Guess a number between 1 and 10</p>
<input type="text" id="guess" />
<input type="button" value="Guess" onclick="submitGuess()" />
</body>
</html>
<p>How to Play:</p>
<ol>
<li>Enter a number between 1 and 10 in the text box.</li>
<li>Click the 'Guess' button.</li>
<li>If your guess is correct, you will be notified. If your guess is wrong, you will be asked to try again.</li>
</ol>
原文地址: https://www.cveoy.top/t/topic/lmj5 著作权归作者所有。请勿转载和采集!