Loading...
intermediate
Problem 04 • Step 02
Play a Turn
This is where everything comes together. playTurn(state, letter) composes all prior functions into a single turn.
It returns an object with:
{
newState, // the updated game state
display, // the word display after this guess
remaining, // remaining unguessed letters
feedback, // "correct", "wrong", "not a letter", or "already guessed"
gameOver, // true if the game has ended
won, // true if the player won
score // the current score (always present, every turn)
}
Rules
- If the guess is invalid,
newStateis the original state unchanged feedbackis the validation reason for invalid guesses, or"correct"/"wrong"for valid ones. You do not need to search the word yourself — compare the old and new state to figure out what happeneddisplayandremainingreflect the new state (after the guess), not the old onescoreis always present, on every turn, not just when the game ends
Each piece was designed and tested in isolation. Composing them should be straightforward. That is the payoff of building with tests.