Workshop › Simon Says Colors › Step 6 of 27
The pads will light up and go dark, so the board must be drawn again and again. We put the drawing lines in a function
named draw, so one word repaints everything.
```js
function draw() {
ctx.fillStyle = '#0f172a'
ctx.fillRect(0, 0, canvas.width, canvas.height)
PADS.forEach((pad, i) => {
const x = (i % 2) * HALF
const y = TOP + Math.floor(i / 2) * HALF
ctx.fillStyle = pad.dim
ctx.fillRect(x + 6, y + 6, HALF - 12, HALF - 12)
})
}
draw()
```function draw() { ... } defines the recipe; it does not run yet.draw() with parentheses runs it. It paints the background first, which wipes the old picture.Wrap the drawing lines in function draw() { ... } (indent them by two spaces) and call draw() after it.
Skills: Functions