Loading...
beginner
Problem 01 • Step 02
Process a Guess
The page has a text input and a Guess button. Look at game.html to see the wiring: each click calls processGuess, then re-renders the board. Right now clicking does nothing because the function is empty.
processGuess(state, letter) takes the current game state and a guessed letter, and returns a new state object (it must not modify the original).
The state object looks like this:
{
word: "apple",
guessedLetters: [],
guessesRemaining: 6
}
Use createGameState(word) (read-only, provided) to create initial states for your tests.
Rules
- The guessed letter (lowercased) is always added to
guessedLetters - If the letter is in the word:
guessesRemainingstays the same - If the letter is not in the word:
guessesRemainingdecreases by 1 - The original state must not be modified. Return a new object
Write tests for both a correct guess and a wrong guess, then implement the function.