Workshop › Hangman › Step 23 of 36
A state says which part of the game we are in: 'playing', 'won' or 'lost'. The sixth miss sets 'lost', and
guess only works while 'playing'.
```js
let state // 'playing', 'won' or 'lost'
function newWord() {
// ...
state = 'playing'
}
function guess(letter) {
if (state !== 'playing' || guessed.has(letter)) return
guessed.add(letter)
if (!word.includes(letter)) wrong += 1
if (wrong === MAX_WRONG) {
state = 'lost'
}
}
```state holds the stage of the game as text. Every new word starts 'playing'.!== means "is not equal to". guess now returns when the game is not being played, which also covers the old
wrong === MAX_WRONG check.state to 'lost'.let wrong write let state ....newWord, at the end, write state = 'playing'.guess, change the first line to if (state !== 'playing' || guessed.has(letter)) return.guess, write the if (wrong === MAX_WRONG) block. Press Run.Skills: Game states
← The parts in a list Winning →