Workshop › Rhythm Lanes › Step 3 of 35
Four lanes with a loop
What we are doing
Four lanes are the same drawing four times, each 70 pixels further right. A for loop repeats it for lane 0, 1, 2
and 3.
```js
for (let lane = 0; lane < LANES; lane++) {
const x = LEFT + lane * LANE_W
ctx.fillStyle = '#1e293b'
ctx.fillRect(x + 2, 0, LANE_W - 4, canvas.height)
}
```
What it means
for (let lane = 0; lane < LANES; lane++) runs its body with lane = 0, 1, 2, 3.
x is where the lane starts: 60, 130, 200, 270.
- The body draws that lane, like before but at
x.
Your turn
Replace the two lane lines at the end with the loop.
Skills: Loops
← The first lane The hit line →
All steps
- A stage for the notes
- The first lane
- Four lanes with a loop
- The hit line
- A function that draws
- The song as text
- From text to notes
- The clock decides where
- Draw the notes
- A clock that ticks
- The game loop
- Lanes that light up
- Keys for the lanes
- Show the keys
- Hit the closest note
- Close enough in time
- One press, one hit
- A message on the screen
- Say Hit
- Let the message go
- Perfect or good
- Keep count
- Missed notes
- Score
- Hits in a row
- The multiplier
- The song ends
- Stop the clock
- Accuracy
- The grade
- The results
- Play again
- Best score
- Lanes you can tap
- Build it yourself: a speed setting