Workshop › Tic-tac-toe › Step 26 of 33
After your X, the computer plays O right away. Only a real move by X, in a round that is not over, gets an answer;
that is what the true/false from play was for.
```js
} else if (player === 'X') {
// The canvas may be displayed at a different size than its 300×300 pixels, so scale the click.
const rect = canvas.getBoundingClientRect()
const x = (event.clientX - rect.left) * (canvas.width / rect.width)
const y = (event.clientY - rect.top) * (canvas.height / rect.height)
const moved = play(Math.floor(y / CELL) * 3 + Math.floor(x / CELL))
if (moved && !result) play(computerMove(board))
}
```else if (player === 'X'): clicks only count when it is X's turn.moved keeps the answer of play: true if X really moved.!result means "no result yet". If both hold, the computer plays computerMove(board).} else { to } else if (player === 'X') {.const index and play(index) lines with the moved line and the computer's move.Skills: Keyboard and mouse input, Game states
← A computer that picks a cell Rule one: take the center →