Workshop › Memory › Step 13 of 25
There are gaps between the cards, and a click in a gap should do nothing. So we ask each card: "is this point inside
you?" cards.find returns the first card that says yes, or undefined.
```js
function cardAt(x, y) {
return cards.find((card) => {
const left = cardX(card)
const top = cardY(card)
return x >= left && x < left + CARD && y >= top && y < top + CARD
})
}
```&& means "and".cards.find(test) returns the first card for which the test is true, or undefined.Under cardY, leave an empty line and write cardAt. Press Run.
Skills: Arrays and objects, Keyboard and mouse input
← A fair shuffle Click to turn a card →