Workshop › Typing Rain › Step 26 of 33

Accuracy

What we are doing

Every key that did not help (a letter no word starts with, or the wrong next letter) is a mistake. Accuracy is the share of keys that were right.

```js
let letters // correct letters typed
let mistakes

  letters = 0
  mistakes = 0

    if (options.length === 0) {
      mistakes += 1
      return
    }

  if (target.text[typed] !== key) {
    mistakes += 1
    return
  }
  typed += 1
  letters += 1

const accuracy = () => (letters + mistakes === 0 ? 100 : Math.round((100 * letters) / (letters + mistakes)))
```

What it means

Your turn

  1. Above let best write let letters and let mistakes; at the end of reset, set both to 0.
  2. In type, turn the two one-line returns into blocks that add a mistake, and add letters += 1 under typed += 1.
  3. Above the keydown listener write accuracy, with an empty line after it.

Skills: Game states, Functions

All steps

  1. A sky for the words
  2. The ground
  3. A word on the canvas
  4. A function that draws
  5. A list of words
  6. Make them fall
  7. The game loop
  8. A new word from the list
  9. Let it rain
  10. Gone past the ground
  11. Lock on to a word
  12. Listen to the keyboard
  13. Letter by letter
  14. Half a word in yellow
  15. Let go of a lost word
  16. Lives
  17. Hearts
  18. Score
  19. Out of lives
  20. Freeze the game
  21. The game over panel
  22. Play again
  23. Levels
  24. Faster and faster
  25. Best score
  26. Accuracy
  27. Words per minute
  28. Your speed at the end
  29. Where the keys go
  30. Draw the keyboard
  31. Light up the next key
  32. Tap the keys
  33. Build it yourself: change your mind