Workshop › Chess › Step 14 of 48
Only the side to move may pick up a piece. turn is 'w' or 'b'; a click on one of your own pieces selects it,
any other click clears the selection.
```js
let turn // 'w' or 'b'
turn = 'w'
function clickSquare(r, c) {
if (board[r][c][0] === turn) {
selected = [r, c]
} else {
selected = null
}
}
```turn starts as 'w' in reset: white moves first.board[r][c][0] is the color of the piece on the square (or undefined if it is empty).else runs when the if condition is false.let board ... write let turn ...; in reset, under the board = ... line write turn = 'w'.clickSquare as shown.Skills: Game states, Keyboard and mouse input
← Light up the selected square Where can it go? →