Loading...
intermediate
Problem 04 • Step 01
Calculate Score
Score = guessesRemaining * number of unique letters in the word.
calculateScore(state) computes the player’s score from the current game state.
Rules
- Count only unique letters in the word.
"apple"has 4 unique letters (a, p, l, e), not 5 - When
guessesRemainingis 0 (the player lost), the score is 0. The multiplication handles this naturally - The score is always a non-negative integer
Examples
calculateScore({ word: "apple", guessedLetters: ["a", "p", "l", "e"], guessesRemaining: 4 })
// 4 * 4 = 16
calculateScore({ word: "apple", guessedLetters: [...], guessesRemaining: 0 })
// 0 * 4 = 0
This step only needs the game state object. No prior functions are required.