Workshop › Wordle-style Word Guess › Step 17 of 26
A guess that matches the answer wins; six that do not, lose. A state remembers which. Once the game is over, keys do
nothing, except Enter, which starts a new word.
```js
let state // 'playing', 'won' or 'lost'
state = 'playing'
function type(key) {
if (state !== 'playing') {
if (key === 'Enter') reset()
return
}
else if (key === 'Enter' && current.length === 5) {
guesses.push({ word: current, marks: score(current, answer) })
if (current === answer) state = 'won'
else if (guesses.length === TRIES) state = 'lost'
current = ''
```'playing'.type returns at once; Enter first calls reset().&& guesses.length < TRIES can go: after six guesses the state is no longer 'playing', so the first check already
stops a seventh.let current, write let state ...; in reset, under current = '', write state = 'playing'.type, write the if (state !== 'playing') block.&& guesses.length < TRIES and write the two state lines under guesses.push(...).Skills: Game states
← Colour the guesses A message line →