Workshop › Pong › Step 14 of 26
Two rectangles overlap when they overlap horizontally and vertically. touches(paddle) checks the four edges and
answers true or false.
```js
function touches(paddle) {
return (
ball.x < paddle.x + PADDLE_W &&
ball.x + BALL > paddle.x &&
ball.y < paddle.y + PADDLE_H &&
ball.y + BALL > paddle.y
)
}
```&& means "and": all four must be true.return span several lines.Under clamp, leave an empty line and write touches. Press Run.
Skills: Collision detection
← Bounce off the top and bottom The paddles hit back →