Workshop › Breakout › Step 17 of 39
A color for every row
What we are doing
Each row gets its own color from a list: red, orange, yellow, green, blue. The brick's row picks the color.
```js
const COLORS = ['#ef4444', '#f97316', '#eab308', '#22c55e', '#3b82f6']
ctx.fillStyle = COLORS[brick.row]
```
What it means
COLORS is an array of five colors, one per row.
COLORS[brick.row] reads the item at that index; counting starts at 0, so row 0 is red.
Your turn
- Under the
const LEFT line write COLORS.
- In
draw, replace '#ef4444' in the brick loop with COLORS[brick.row].
Skills: Arrays and objects
← A whole wall: a loop inside a loop Circle meets box →
All steps
- The field and the paddle
- Draw again and again
- Keep a number inside limits
- Follow the mouse
- A canvas shown at another size
- A ball with a velocity
- Draw a round ball
- Move the ball
- Bounce off the side walls
- Bounce off the ceiling
- The open floor
- Bounce off the paddle
- Aim with the paddle
- A row of bricks
- Draw the bricks
- A whole wall: a loop inside a loop
- A color for every row
- Circle meets box
- Break a brick
- Hitting the side of a brick
- Wait on the paddle
- Ride along with the paddle
- Launch the ball
- Click or press Space
- Remember which keys are held
- Steer with the arrow keys
- Three lives
- Lives and a hint on screen
- Game over
- Keep score
- Show the score
- Win the game
- One function for a new game
- Play again
- A burst of particles
- Break into sparks
- Move, fall and disappear
- Fade out
- Build it yourself: tough bricks