Learn by Building Workshop Skills GitHub Türkçe Workshop › Tic-tac-toe › Step 17 of 33
The eight winning lines What we are doing Three in a row wins. There are only 8 such lines: 3 rows, 3 columns, 2 diagonals. We write them down once, as data,
instead of writing a long chain of ifs.
```js
const LINES = [
[0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
[0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
[0, 4, 8], [2, 4, 6], // diagonals
]
```What it means
LINES is an array of arrays: 8 items, each a small array of 3 cell numbers.
[0, 1, 2] is the top row; [0, 3, 6] the left column; [0, 4, 8] a diagonal.
A list can span several lines; the // comments are only notes.
Your turn Write LINES right under const CELL = 100. Press Run .
Skills: Arrays and objects
← Clicks on any screen size Find three in a row →
All steps Get the canvas and the pen Paint the board The first grid line Repeat with a loop Finish the grid The board as a list A function that draws Write an X From cell number to position Draw what the board holds A color for each mark Make a move No playing on a taken cell Listen for clicks Which cell was clicked? Clicks on any screen size The eight winning lines Find three in a row Win, draw or go on The round ends Show who won Light up the winning line A function for a fresh round Click to play again A computer that picks a cell The computer answers Rule one: take the center Rule two: win when you can Rule three: block the opponent Score a finished game Look ahead: minimax A computer that never loses Build it yourself: keep score