A word scramble game shows you a jumbled word and asks you to unscramble it against the clock. It is a perfect beginner project because it is mostly string manipulation — shuffling, comparing, and scoring — with a small amount of UI, and it works just as well as a study tool as it does as a game.
The word list is the content. Group words by theme so the game feels like it is teaching something — animals, coding terms, or everyday objects — and let the player pick a theme. Each round picks a random word and shuffles its letters:
const WORDS = {
animals: ["elephant", "giraffe", "dolphin", "penguin", "kangaroo"],
coding: ["function", "variable", "javascript", "database", "compiler"],
food: ["sandwich", "chocolate", "pancakes", "spaghetti", "avocado"],
};
function shuffleWord(word) {
const letters = word.split("");
for (let i = letters.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[letters[i], letters[j]] = [letters[j], letters[i]];
}
return letters.join("");
}
One detail matters: the shuffled word must not accidentally equal the original. For short words this happens often, so reshuffle until it differs:
function newRound() {
const list = WORDS[currentTheme];
currentWord = list[Math.floor(Math.random() * list.length)];
let scrambled = shuffleWord(currentWord);
while (scrambled === currentWord) {
scrambled = shuffleWord(currentWord);
}
document.getElementById("scrambled").textContent = scrambled;
document.getElementById("guess").value = "";
document.getElementById("guess").focus();
}
Guessing is a comparison, but normalise both sides first — lowercase and trim — so "Elephant" and "elephant " both count. A hint button reveals one letter at a time and costs points, which teaches a useful design lesson: hints should cost something, or players will just click through:
function checkGuess() {
const guess = document.getElementById("guess").value.trim().toLowerCase();
if (guess === currentWord) {
score += 10;
document.getElementById("score").textContent = score;
document.getElementById("message").textContent = "Correct! Next word...";
setTimeout(newRound, 800);
} else {
document.getElementById("message").textContent = "Not quite — try again!";
}
}
let hinted = 0;
function showHint() {
if (hinted >= currentWord.length - 1) return;
hinted++;
score = Math.max(0, score - 2);
const hint = currentWord.slice(0, hinted) + "_".repeat(currentWord.length - hinted);
document.getElementById("hint").textContent = hint;
}
A timer turns it from a toy into a game. Sixty seconds, one interval, and the round ends when time runs out — with the final score and a restart button:
let timeLeft = 60;
const timer = setInterval(() => {
timeLeft--;
document.getElementById("time").textContent = timeLeft;
if (timeLeft <= 0) {
clearInterval(timer);
document.getElementById("message").textContent = `Time's up! Final score: ${score}`;
}
}, 1000);
Ways to extend it: add difficulty levels with longer words, add a streak bonus that grows with consecutive correct answers, store the best score per theme in localStorage, or add a "reveal letter" animation that flips each letter into place. The shuffle algorithm here — Fisher-Yates — is the same one used in card games and quiz apps, so it is worth learning by heart.
Top comments (0)