Workshop › Tower Defense › Step 34 of 42
The score is how many waves you survived. The best one is kept in the browser's localStorage, so it is still there
after a reload.
```js
let best = Number(localStorage.getItem('td-best')) || 0
if (wave - 1 > best) {
best = wave - 1
localStorage.setItem('td-best', best)
}
if (wave > best) {
best = wave
localStorage.setItem('td-best', best)
}
```localStorage.getItem('td-best') reads the saved text (null the first time); Number(...) makes it a number and
|| 0 falls back to 0.wave - 1; at the end of a wave it is wave.setItem saves the new record.let hover = null, write the best line.lives block, save the record before return.Skills: Game states
← No building after the end The game over screen →