Loading...
beginner
Problem 02 • Step 02
Wire Validation
Now bring it together. processGuessValidated(state, letter) should:
- Validate the guess using
validateGuess(provided as read-only) - If invalid, return the state unchanged
- If valid, process the guess normally. Add the letter, decrement on a miss
Look at game.html to see how this changes the game: the button handler now calls processGuessValidated instead of processGuess directly. If the state does not change, the game shows “Invalid guess.”
Rules
- Invalid guesses (non-letters, duplicates) return the exact same state
- A duplicate wrong guess must not decrement
guessesRemainingagain - Valid guesses work like the
processGuessyou built earlier
Examples
let state = { word: "apple", guessedLetters: [], guessesRemaining: 6 };
processGuessValidated(state, "a")
// { word: "apple", guessedLetters: ["a"], guessesRemaining: 6 }
processGuessValidated(state, "7")
// state unchanged, "7" is not a letter
let after = processGuessValidated(state, "z");
processGuessValidated(after, "z")
// after unchanged, "z" already guessed, no double penalty