0PricingLogin
Javascript for Kids · Lesson

Star Triangles

Grow shapes.

Growing Shapes! 🔺

What if each row had MORE stars than the last? You get a triangle! 🔺

Row 1: *
Row 2: **
Row 3: ***

Let us make shapes that GROW! 🌱

The Secret Trick 🪄

The magic: the inner loop runs as many times as the OUTER counter!

So when the row number grows, the number of stars grows too!

for (let r = 1; r <= 4; r++) {
  let row = ''
  for (let c = 1; c <= r; c++) {
    row = row + '*'
  }
  console.log(row)
}

All lessons in this course

  1. A Loop Inside a Loop
  2. Rows and Columns
  3. Star Triangles
  4. A Times Table
← Back to Javascript for Kids