Simple HTML Word Guessing Game - Fun and Easy to Play!
<html>
<head>
<title>Guess the Word Puzzle</title>
</head>
<body>
<h1>Guess the Word Puzzle</h1>
<div>
<p>Welcome to the game! Can you guess the word below?</p>
<p>
<span id='word'>----</span>
</p>
<input type='text' id='guessInput'>
<button type='button' id='guessButton'>Guess</button>
</div>
<script>
let word = 'JAVASCRIPT';
let guessInput = document.getElementById('guessInput');
let guessButton = document.getElementById('guessButton');
let wordSpan = document.getElementById('word');
<pre><code> guessButton.addEventListener('click', function(){
if(word === guessInput.value.toUpperCase()) {
alert('That's right! You guessed it!');
wordSpan.innerHTML = word;
} else {
alert('Sorry, try again!');
}
});
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmly 著作权归作者所有。请勿转载和采集!