Workshop › Missile Command-style Defense › Step 34 of 35
The best score is saved in the browser's localStorage when a game ends, so it survives a page reload, and it is shown
next to the score.
```js
let best = Number(localStorage.getItem('missile-best')) || 0
if (score > best) {
best = score
localStorage.setItem('missile-best', best)
}
ctx.fillText('Score ' + score + ' Best ' + best, 10, 22)
```localStorage.getItem reads the saved text (or null); Number turns it into a number; || 0 covers the first
game.best is updated and saved with setItem.let pause write the best line.update, in the lost-cities block, write the if (score > best) block between state = 'over' and return.draw, add + ' Best ' + best to the score text.Skills: Game states
← Split into three Build it yourself: a crosshair →