Workshop › Tic-tac-toe › Step 20 of 33
The rules exist, but the game ignores them: you can keep playing after a win. We keep the round's result in
result, update it after every move, and refuse moves once it is set.
```js
let result = null // null while playing, then 'X', 'O' or 'draw'
function play(index) {
if (result || board[index] !== '') return false
board[index] = player
player = player === 'X' ? 'O' : 'X'
result = outcome(board)
return true
}
```result starts as null: the round is still going.result || ... means "or": if the round is over, or the cell is taken, no move.result = outcome(board) records a win or a draw.let player = 'X', write the result line.play, add result || to the if, and write result = outcome(board) under the line that switches player.Skills: Game states
← Win, draw or go on Show who won →