Random Number Guessing Game in HTML - Play Now!
Random Number Guessing Game
Guess a number between 1 and 10 and see if you can guess the right number!
<script>
// Generate a random number between 1 and 10
let randomNumber = Math.floor(Math.random() * 10) + 1;
// Prompt the user for their guess
let guess = prompt('Guess a number between 1 and 10');
// Check to see if their guess matches the random number
if (parseInt(guess) === randomNumber) {
document.write('<p>You guessed the number!</p>');
} else {
document.write('<p>Sorry, the number was ' + randomNumber + '</p>');
}
</script>
原文地址: https://www.cveoy.top/t/topic/lmsj 著作权归作者所有。请勿转载和采集!