Workshop › Snake › Step 12 of 28
A snake is more than a head: it is a list of cells. We keep them in an array and draw every one with a loop.
```js
let snake = [
{ x: 5, y: 5 },
{ x: 4, y: 5 },
{ x: 3, y: 5 },
]
ctx.fillStyle = 'lime'
for (const part of snake) {
ctx.fillRect(part.x * CELL, part.y * CELL, CELL, CELL)
}
```[ ... ] is an array: a list in order. The first item (index 0) is the head.for (const part of snake) repeats its body once for each item, calling the current one part.let head = ... write the snake array.draw, replace the lime fillRect line with the for loop.Skills: Arrays and objects
← Steer with the arrow keys Move the whole body →