Workshop › Breakout › Step 27 of 39
Each lost ball costs one of three lives. With lives left, the ball goes back to the paddle; with none, the game is
'lost' and the ball stops.
```js
let lives = 3
if (state !== 'playing') return
if (ball.y - BALL_R > canvas.height) {
lives -= 1
if (lives === 0) state = 'lost'
else resetBall()
}
```lives starts at 3; lives -= 1 takes one away.if ... else: with no lives left the game is lost, otherwise the ball goes back to serving.if (state !== 'playing') return stops update in any state other than playing, so a lost ball stays put.let state write let lives = 3.update, right under the serve block's }, write if (state !== 'playing') return.update with the new if block.Skills: Game states
← Steer with the arrow keys Lives and a hint on screen →