Word Guessing Game
Fun with forms. This script challenges the user to guess a hidden word, providing feedback on whether they are correct or need to try again.
Guess the Secret Word (Hint: Programming Language)
...
Copy the Script
<script>
var secret = "JAVASCRIPT";
function checkGuess() {
var userGuess = document.getElementById("guess").value.toUpperCase();
if (userGuess === secret) {
alert("You won!");
} else {
alert("Try again.");
}
}
</script>
<input type="text" id="guess" placeholder="Guess the word">
<button onclick="checkGuess()">Check</button>
Frequently Asked Questions
Usually, game logic converts both the secret word and user input to `.toUpperCase()` to ensure 'Apple' matches 'apple'.
Yes. You can store words as objects: `{word: 'APPLE', hint: 'A red fruit'}` and display the hint property when the game starts.
This simple version checks for an exact match. You can easily add a counter variable to limit the user to 3 or 5 tries.