Workshop › Breakout › Step 12 of 39
The ball should bounce off the paddle's top face. We ask five questions at once and store the answer in onPaddle.
```js
const onPaddle =
ball.vy > 0 &&
ball.y + BALL_R >= PADDLE_Y &&
ball.y + BALL_R <= PADDLE_Y + PADDLE_H + ball.vy &&
ball.x >= paddle.x &&
ball.x <= paddle.x + PADDLE_W
if (onPaddle) {
ball.vy = -Math.abs(ball.vy)
ball.y = PADDLE_Y - BALL_R
}
```&& means "and": onPaddle is true only when all five parts are true.-Math.abs(ball.vy) is always negative: up. ball.y = PADDLE_Y - BALL_R puts the ball on top of the paddle.In update, between the ceiling if and the last line, leave an empty line on both sides and write the paddle check.
Skills: Collision detection
← The open floor Aim with the paddle →