Workshop › Connect Four › Step 5 of 38
A whole row
What we are doing
Seven holes in a row: instead of writing seven calls, a for loop repeats one call for each column, 0 to 6.
```js
for (let col = 0; col < COLS; col++) {
const x = col * CELL + CELL / 2
const y = TOP + CELL / 2
disc(x, y, '#0f172a')
}
```
What it means
for (let col = 0; col < COLS; col++): start with col at 0, repeat while it is below 7, add 1 after each turn.
x moves one cell to the right each time: 32, 96, 160, ...
Your turn
Replace the single disc(...) call with the loop.
Skills: Loops
← One hole All 42 holes →
All steps
- A dark background
- A drawing function
- The blue board
- One hole
- A whole row
- All 42 holes
- The board in memory
- Discs in their colors
- Draw every frame
- Where does the disc land?
- Play a column
- Taking turns
- Click to play
- The next disc
- Whose turn?
- Playing with the keyboard
- Keys 1 to 7
- A disc on its way
- Gravity
- Watch it fall
- Inside the board?
- Walking along a line
- Four in a row?
- We have a winner
- Circle the four
- Who won?
- A draw
- Play again
- Try a move and take it back
- Win, or block
- Don't help the player
- Prefer the middle
- The computer's turn
- Only on your turn
- You and the computer
- Counting wins
- Show the score
- Build it yourself: the loser starts