Workshop › Breakout › Step 19 of 39
Every frame, find the first living brick the ball touches. If there is one, it dies and the ball bounces back.
```js
// Break at most one brick per frame, or two flips could cancel out.
const brick = bricks.find((b) => b.alive && hitsBrick(b))
if (brick) {
brick.alive = false
ball.vy = -ball.vy
}
```bricks.find(...) returns the first brick for which the arrow function returns true, or undefined.if (brick) is true only when a brick was found.In update, write the block between the paddle check's closing } and the last if, with an empty line on both
sides.
Skills: Collision detection, Arrays and objects
← Circle meets box Hitting the side of a brick →