Workshop › Chess › Step 18 of 48
A click on one of the dots plays that move. So clickSquare first looks for a target move ending on the clicked
square; if there is one, it plays it and stops.
```js
function clickSquare(r, c) {
const move = targets.find((m) => same(m.to, [r, c]))
if (move) {
play(move)
return
}
```find returns the first item for which the function is true, or undefined.play it; return ends clickSquare there, so the selection code below does not run.At the top of clickSquare, above the if (board[r][c][0] === turn) line, write the new lines.
Skills: Keyboard and mouse input
← Play a move Say whose turn it is →