Workshop › Connect Four › Step 1 of 38
Drop discs into the columns and get four in a row before the computer does. A 2D array with gravity, a falling animation, checking lines in four directions, and a computer opponent that wins, blocks and thinks one move ahead.
We are building Connect Four: drop discs into columns and get four in a row before the computer does. Everything is
painted on a <canvas>. First we find it, take its drawing tool and paint the background dark.
```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')
ctx.fillStyle = '#0f172a'
ctx.fillRect(0, 0, canvas.width, canvas.height)
```document.getElementById('game') finds the canvas; const canvas = gives it a name.getContext('2d') gives its drawing tool, ctx.fillStyle picks a color; fillRect(x, y, width, height) paints a rectangle, here the whole canvas.Write the code under the three comment lines and press Run.
Skills: Drawing on a canvas