Workshop › Tic-tac-toe › Step 19 of 33
outcome(cells) sums up a board in one word: 'X' or 'O' if someone has three in a row, 'draw' if the board is
full, and null while the game goes on.
```js
function outcome(cells) {
const line = winningLine(cells)
if (line) return cells[line[0]]
if (cells.every((cell) => cell !== '')) return 'draw'
return null
}
```cells.every(test) is true when every cell passes: all filled means a draw.null means "nothing yet". Order matters: a win on the last move is checked before the draw.Under winningLine, leave an empty line and write outcome (still above function play). Press Run.
Skills: Functions, Arrays and objects
← Find three in a row The round ends →