Workshop › Pinball › Step 35 of 42
The best score is kept in localStorage, the browser's small notebook that survives closing the page. It is read
when the page loads and saved when a game ends with a new record.
```js
let best = Number(localStorage.getItem('pinball-best')) || 0
state = 'over'
if (score > best) {
best = score
localStorage.setItem('pinball-best', best)
}
ctx.font = '13px sans-serif'
ctx.fillText('Best ' + best, 200, 50)
```localStorage.getItem(name) reads a saved value as text, or null if there is none. Number(...) makes it a
number; || 0 uses 0 when that gives nothing useful.setItem saves it under the same name.Best is written in the middle of the top, smaller than the rest.let flash write let best = ....update, inside the else block, under state = 'over', write the if block.draw, under ctx.textAlign = 'center', write the two Best lines.Skills: Game states
← Play again Launch on letting go →