Simple HTML Guessing Game: Learn to Code with This Easy Example
<html>
<head>
<title>Guess The Number</title>
</head>
<body>
<script>
// Generate a random number between 1 and 10
const randomNumber = Math.ceil(Math.random() * 10);
<pre><code> // Ask the user to guess the number
const guess = prompt('Guess a number between 1 and 10');
// Check if the guess is correct
if(parseInt(guess) === randomNumber) {
alert('You guessed the number!');
} else {
alert('Sorry, wrong answer. The number was ' + randomNumber);
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmni 著作权归作者所有。请勿转载和采集!