Workshop › Lunar Lander › Step 27 of 31
When a game ends with a crash, a score higher than the best is saved in the browser's localStorage, and the best is
shown next to the score.
```js
let best = Number(localStorage.getItem('lander-best')) || 0
if (score > best) {
best = score
localStorage.setItem('lander-best', best)
}
ctx.fillText('Level ' + level + ' Score ' + score + ' Best ' + best, canvas.width - 10, 20)
```getItem reads the saved text (or null); Number turns it into a number; || 0 covers the very first game.touchdown, after a crash, a better score is saved with setItem.const keys = {} write the best line.touchdown, under state = 'crashed', write the if (score > best) block.draw, add + ' Best ' + best to the top-right text.Skills: Game states
← A narrower pad Burst into pieces →