Workshop › Space Invaders-style › Step 16 of 21

Best score

What we are doing

The best score is kept in localStorage, so it survives closing the page, and is shown on the GAME OVER band. The band already promises that Space plays again; the next steps make that true.

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

  if (score > best) {
    best = score
    localStorage.setItem('invaders-best', best)
  }

    ctx.font = '16px monospace'
    ctx.fillText('BEST ' + best + '   SPACE TO PLAY AGAIN', canvas.width / 2, 290)
```

What it means

Your turn

  1. Under now, write best.
  2. In endGame, save a new record.
  3. In the GAME OVER band, write the best score line.

Skills: Game states

All steps

  1. The ship
  2. The game loop
  3. Move the ship
  4. Stay on screen
  5. Fire
  6. Bullets fly
  7. A short reload
  8. The invaders
  9. The march
  10. Hit!
  11. Score
  12. They shoot back
  13. Bombs fall
  14. Lives
  15. Game over
  16. Best score
  17. A wave in a function
  18. Play again
  19. Waves
  20. Faster and faster
  21. Build it yourself: an extra life