Lesson 33

Loop Practice

Practice exercises with loops

20 min
+25 XP
Step 1 of 5

Exercise 1: Print Star Patterns

Challenge:

Create a pattern where each line has one more star than the previous line.

The Code:

let rows = 5

for (let i = 0; i < rows; i++) {
  let stars = ""
  for (let j = 0; j <= i; j++) {
    stars += "*"
  }
  console.log(stars)
}

Try It Yourself!

Tip:

Notice how we use i in the inner loop's condition. Each row prints exactly i + 1 stars!