Workshop › OutRun-style Racer › Step 38 of 44
When a lap ends, its time is compared with the best lap so far. Fewer frames is better, so a lap is a record when there
is no record yet or it is smaller. The record is saved in localStorage, so it stays after the page is closed.
```js
let best = Number(localStorage.getItem('racer-best')) || 0
position -= trackLength
if (best === 0 || lapTime < best) {
best = lapTime
localStorage.setItem('racer-best', best)
}
lap += 1
```localStorage.getItem reads the saved text (or null); Number(...) || 0 turns it into a number, or 0 if there is
none. 0 means "no record yet".|| means "or": no record yet, or a faster lap. Then it becomes the best and is saved with setItem.let lapTime write the best line.position -= trackLength and lap += 1, write the record if.Skills: Game states
← Show the time Show the best lap →