Workshop › Sudoku › Step 24 of 28

Best time

What we are doing

The fastest solve is saved in localStorage, but only if no hint was used. The best time and the hints so far are shown on the right.

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

  const seconds = Math.floor(frames / 60)
  if (hints === 0 && (best === 0 || seconds < best)) {
    best = seconds
    localStorage.setItem('sudoku-best', best)
  }

  ctx.textAlign = 'right'
  ctx.fillText('Best ' + (best ? clock(best) : '-') + '  Hints ' + hints, canvas.width - LEFT, 34)
```

What it means

Your turn

  1. Under let hints, write best.
  2. At the end of checkWin, save the record.
  3. In draw, under the Time line, write the right-aligned line.

Skills: Game states

All steps

  1. Nine by nine
  2. Lines and boxes
  3. A puzzle from a string
  4. The puzzle's own digits
  5. Keep drawing
  6. The selected cell
  7. Light up row, column and box
  8. The same digit everywhere
  9. Click to select
  10. Move with the arrows
  11. Write digits
  12. The three rules in one loop
  13. Show mistakes
  14. Solved!
  15. A clock
  16. The solved message
  17. Play again
  18. The easiest cell
  19. The solver
  20. Random order
  21. Invent a puzzle
  22. A new puzzle every game
  23. Hints
  24. Best time
  25. N for a new puzzle
  26. A number pad
  27. Tap the pad
  28. Build it yourself: undo