Workshop › Angry Birds-style Slingshot › Step 45 of 47
When the last level is won, the total score can become your best. It is kept in localStorage, the browser's little
notebook that survives closing the page, and shown in the top-right corner.
```js
let best = Number(localStorage.getItem('birds-best')) || 0
state = 'won'
if (level === LEVELS.length - 1 && score > best) {
best = score
localStorage.setItem('birds-best', best)
}
ctx.textAlign = 'right'
ctx.fillText('Best ' + best, canvas.width - 10, 22)
```localStorage.getItem('birds-best') reads the saved text (or null the first time); Number(...) turns it into a
number and || 0 falls back to 0.setItem.textAlign = 'right' makes x the right end of the text, 10 pixels from the right edge.let calm write the best line.update, under state = 'won', write the saving if.draw, under the Level ... text, write the two Best lines.Skills: Game states
← On to the next level The right words →