Workshop › Candy Crush-style Match 3 › Step 28 of 29
The best score is kept in localStorage, the browser's small notebook that survives closing the page. When the last
move has settled and the score beats it, it is saved.
```js
let best = Number(localStorage.getItem('match3-best')) || 0
function afterMoves() {
if (movesLeft === 0 && score > best) {
best = score
localStorage.setItem('match3-best', best)
}
}
afterMoves()
ctx.fillText('Moves ' + movesLeft + ' Best ' + best, canvas.width - LEFT, 30)
```localStorage.getItem(name) reads a saved value as text, or null. Number(...) makes it a number and || 0 uses
0 when there is nothing.afterMoves saves a new record once the moves are used up; it runs when a move has completely settled.let hint write let best = ....function update() { write afterMoves.update, under while (!hasMove()) newBoard(), call afterMoves().draw, add + ' Best ' + best to the Moves text.Skills: Game states
← The end of a game Build it yourself: swipe to swap →