Workshop › Pong › Step 6 of 26
A game redraws its picture many times a second. We put the drawing lines in a function named draw, so one word
repaints everything.
```js
function draw() {
ctx.fillStyle = 'black'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = 'white'
for (let y = 0; y < canvas.height; y += 30) {
ctx.fillRect(canvas.width / 2 - 2, y, 4, 15)
}
ctx.fillRect(left.x, left.y, PADDLE_W, PADDLE_H)
ctx.fillRect(right.x, right.y, PADDLE_W, PADDLE_H)
}
draw()
```function draw() { ... } defines the recipe; it does not run yet.draw() with parentheses runs it. It paints the court black first, which wipes the old picture.Wrap all the drawing lines in function draw() { ... } (indent them by two spaces) and call draw() after it.
Skills: Functions