Workshop › Sokoban › Step 27 of 29
Keep the fewest moves for each level in an object keyed by level number, and save it in localStorage as JSON
text so it survives closing the page.
```js
let best = JSON.parse(localStorage.getItem('sokoban-best') || '{}') // fewest moves, per level
moves += 1
if (solved() && (best[level] === undefined || moves < best[level])) {
best[level] = moves
localStorage.setItem('sokoban-best', JSON.stringify(best))
}
```localStorage.getItem gives the saved text, or null the first time; || '{}' then uses an empty object's text,
and JSON.parse turns it into an object.best[level] is the record of this level, undefined until it is solved once.let history write the best line.move, under moves += 1, write the if block. Press Run.Skills: Game states