Workshop › Flappy-style Bird › Step 26 of 30
The best score is kept in localStorage, the browser's little notebook, which survives page reloads. It is read once
at the start and updated when a game ends with a better score.
```js
let best = Number(localStorage.getItem('flappy-best')) || 0
function endGame() {
state = 'over'
if (score > best) {
best = score
localStorage.setItem('flappy-best', best)
}
}
```localStorage.getItem('flappy-best') reads the saved text, or null if there is none.Number(...) turns the text into a number; || 0 uses 0 when there is no best yet.endGame, a higher score becomes the new best and is saved with setItem.let state // ..., write the best line.endGame, under state = 'over', write the if block.Skills: Game states
← One place where the game ends Show the best score →