Workshop › Hangman › Step 29 of 36
A winning streak
What we are doing
A streak counts words solved in a row. A win adds one; a loss sets it back to 0.
```js
let streak = 0
if ([...word].every((l) => guessed.has(l))) {
state = 'won'
streak += 1
} else if (wrong === MAX_WRONG) {
state = 'lost'
streak = 0
}
ctx.fillText('Streak ' + streak, 260, 70)
```
What it means
streak starts at 0 once, when the page loads; newWord does not touch it, so it lives across words.
- A win adds one, a loss resets it.
- It is drawn above the misses, with the same font and color.
Your turn
- Under
let state ... write let streak = 0.
- In
guess, under state = 'won' write streak += 1; under state = 'lost' write streak = 0.
- In
draw, above the Misses line, write the Streak line. Press Run.
Skills: Game states
← Never the same word twice Remember the best streak →
All steps
- A list of secret words
- The canvas and the pen
- Paint the paper
- A function that draws
- Pick a random word
- Write the word
- Hide it behind blanks
- Remember the guesses
- Draw again and again
- A guess
- Guess with the keyboard
- Only letters count
- Count the misses
- The same letter twice is free
- Six misses at most
- Show the misses
- List the wrong letters
- Draw a line
- The gallows
- The first miss: a head
- Body, arms and legs
- The parts in a list
- Losing
- Winning
- Show the word you missed
- The end message
- Play again
- Never the same word twice
- A winning streak
- Remember the best streak
- Where each key goes
- Draw the keys
- Center the last row
- Keys that remember
- Tap a key
- Build it yourself: a hint button