Workshop › Pool › Step 32 of 33
The fewest shots you ever needed to clear the table is your best. It is kept in localStorage, which the browser keeps
even after the page is closed, and shown at the top right.
```js
let best = Number(localStorage.getItem('pool-best')) || 0
if (best === 0 || shots < best) {
best = shots
localStorage.setItem('pool-best', best)
}
ctx.textAlign = 'right'
ctx.fillText('Best ' + (best || '-'), RIGHT, 22)
```localStorage.getItem reads a saved text (or null); Number(...) makes it a number; || 0 uses 0 when there is none.best || '-' shows the number, or - while it is 0.let state ... write let best = ....update, under state = 'won', write the if block.draw, under the Shots text line, write the two Best lines.Skills: Game states
← Where the hit ball goes Build it yourself: two players →