Workshop › Hangman › Step 8 of 36

Remember the guesses

What we are doing

The letters you have tried go into a Set. masked() then shows a letter if it is in the Set, and _ if not.

```js
let word
let guessed // a Set of the letters tried so far

// The word with the letters not guessed yet hidden: 'C _ S T _ E'.
const masked = () => [...word].map((letter) => (guessed.has(letter) ? letter : '_')).join(' ')

function newWord() {
  word = WORDS[Math.floor(Math.random() * WORDS.length)]
  guessed = new Set()
}
```

What it means

Your turn

  1. Under let word write let guessed ....
  2. Write the comment above masked, and change its '_' to the ? : form.
  3. In newWord, under the word = ... line, write guessed = new Set(). Press Run.

Skills: Arrays and objects, Game states

All steps

  1. A list of secret words
  2. The canvas and the pen
  3. Paint the paper
  4. A function that draws
  5. Pick a random word
  6. Write the word
  7. Hide it behind blanks
  8. Remember the guesses
  9. Draw again and again
  10. A guess
  11. Guess with the keyboard
  12. Only letters count
  13. Count the misses
  14. The same letter twice is free
  15. Six misses at most
  16. Show the misses
  17. List the wrong letters
  18. Draw a line
  19. The gallows
  20. The first miss: a head
  21. Body, arms and legs
  22. The parts in a list
  23. Losing
  24. Winning
  25. Show the word you missed
  26. The end message
  27. Play again
  28. Never the same word twice
  29. A winning streak
  30. Remember the best streak
  31. Where each key goes
  32. Draw the keys
  33. Center the last row
  34. Keys that remember
  35. Tap a key
  36. Build it yourself: a hint button