Workshop › Zelda-style Dungeon › Step 21 of 22

Best time

What we are doing

The fastest escape is kept in localStorage and shown next to the time. Here the best is the smallest number of frames.

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

    if (best === 0 || frames < best) {
      best = frames
      localStorage.setItem('dungeon-best', best)
    }

  ctx.fillText('Time ' + seconds(frames) + (best ? '  Best ' + seconds(best) : ''), canvas.width - 12, 30)
```

What it means

Your turn

  1. Above held, write best.
  2. In the stairs block, save a new record.
  3. Add the best time to the time text.

Skills: Game states

All steps

  1. A room
  2. The hero
  3. The game loop
  4. Walk
  5. Walls
  6. A touch pad
  7. Next room
  8. The sword
  9. Enemies
  10. Strike!
  11. They chase you
  12. They wander
  13. Ouch
  14. Blinking and hearts
  15. Keys and hearts
  16. A world that remembers
  17. The locked door
  18. A timer
  19. Game over
  20. The stairs out
  21. Best time
  22. Build it yourself: cleared rooms