Workshop › Endless Runner › Step 14 of 19

Remember the best run

What we are doing

The score is the distance divided by 10. When a run ends with a new record, it is saved in the browser's localStorage.

```js
let best = Number(localStorage.getItem('runner-best')) || 0

    const score = Math.floor(distance / 10)
    if (score > best) {
      best = score
      localStorage.setItem('runner-best', best)
    }
```

What it means

Your turn

  1. Under let nextIn, write the best line.
  2. In the crash block of update, work out the score and save a record.

Skills: Game states

All steps

  1. The ground
  2. The runner
  3. Draw again and again
  4. Gravity
  5. Jump
  6. Short hops
  7. Tap to jump
  8. Things that come at you
  9. Cacti keep coming
  10. Wait for the start
  11. Crash
  12. Try again
  13. Faster and faster
  14. Remember the best run
  15. The score counter
  16. Birds
  17. Which keys are down?
  18. Duck
  19. Build it yourself: jump buffering