Workshop › Chess › Step 27 of 48
A king is in check when its square is attacked by the other side. findKing finds the king's square, inCheck
asks attacked about it.
```js
function findKing(color) {
for (let r = 0; r < 8; r++) {
for (let c = 0; c < 8; c++) if (board[r][c] === color + 'K') return [r, c]
}
}
function inCheck(color) {
const [r, c] = findKing(color)
return attacked(r, c, other(color))
}
```findKing scans the board and returns the square of that color's king.for or if with a single line can skip the braces.inCheck unpacks the square and asks whether the other color attacks it.Above function play(m) {, write findKing and inCheck, each followed by an empty line.
Skills: Functions
← Attacks from far away A move that remembers →