Workshop › Pool › Step 22 of 33
When everything stops and only the cue ball is left, the table is cleared: the state becomes 'won' and a message shows
the number of shots. Space then starts again.
```js
if (balls.length === 1) {
state = 'won'
} else state = 'aiming'
else if (event.key === ' ') state === 'won' ? reset() : shoot()
if (state === 'won') {
ctx.textAlign = 'center'
ctx.font = 'bold 22px sans-serif'
ctx.fillText('Table cleared in ' + shots + ' shots!', canvas.width / 2, 170)
}
```state === 'won' ? reset() : shoot() restarts after a win and shoots otherwise.update, replace state = 'aiming' (the last line) with the if/else.draw, under the Shots text, write the if (state === 'won') block.Skills: Game states
← Balls left Choose the power →