Learn by Building Workshop Skills GitHub Türkçe Workshop › Tic-tac-toe › Step 9 of 33
From cell number to position What we are doing The board array numbers the cells 0 to 8. To draw a mark we need the cell's center in pixels. Two small formulas
turn a cell number into a column and a row.
```js
const index = 7
const x = (index % 3) * CELL + CELL / 2
const y = Math.floor(index / 3) * CELL + CELL / 2
ctx.fillText('X', x, y)
```What it means
% is the remainder: 7 % 3 is 1, so cell 7 is in column 1.
Math.floor(7 / 3) rounds 2.33 down to 2, so it is in row 2.
* CELL turns the column or row into pixels, + CELL / 2 moves to the middle of the cell: (150, 250).
Your turn In draw, replace ctx.fillText('X', 50, 50) with the four new lines. Press Run .
Skills: Arrays and objects
← Write an X Draw what the board holds →
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