Learn by Building Workshop Skills GitHub Türkçe Workshop › Connect Four › Step 2 of 38
A drawing function What we are doing The picture will change as discs drop, so we need to be able to draw it again and again. We put the drawing lines into a
function called draw, and call it.
```js
function draw() {
ctx.fillStyle = '#0f172a'
ctx.fillRect(0, 0, canvas.width, canvas.height)
}
draw()
```What it means
function draw() { ... } defines the recipe; it does not run yet.
The lines between { and } are its body, indented by two spaces.
draw() with parentheses runs it.
Your turn Put function draw() { above the two painting lines, indent them, close with }, and call draw() below.
Skills: Functions
← A dark background The blue board →
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