Workshop › Whack-a-Mole › Step 7 of 18
A click gives a point on the canvas. holeAt finds the hole whose circle contains that point, using the distance to
the hole's middle (Pythagoras).
```js
function holeAt(x, y) {
return holes.find((hole) => {
const dx = x - hole.x
const dy = y - hole.y
return dx * dx + dy * dy <= HOLE_R * HOLE_R
})
}
```find returns the first hole for which the function returns true, or undefined if none does.dx and dy are how far the point is from the hole's middle, sideways and up/down.dx² + dy² with R² avoids a square root.Above update, write holeAt.
Skills: Collision detection