Workshop › Typing Rain › Step 25 of 33
The best score is saved in localStorage when the game ends, so it is still there next time, and shown next to the
hearts.
```js
let best = Number(localStorage.getItem('typing-best')) || 0
function gameOver() {
state = 'over'
if (score > best) {
best = score
localStorage.setItem('typing-best', best)
}
}
ctx.fillText('♥'.repeat(lives) + ' Best ' + best, canvas.width - 10, 22)
```getItem reads the saved text (or null); Number(...) || 0 makes it a number, 0 the first time.gameOver saves a better score with setItem.let state write let best.gameOver, under state = 'over', write the if block.draw, add the best score to the hearts text.Skills: Game states
← Faster and faster Accuracy →