0Pricing
Javascript for Kids · Lesson

Star Triangles

Grow shapes.

Star Triangles is a free Javascript for Kids lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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)
}

See It Grow 🌱

Notice c <= r! The inner loop stops at the row number. Row 1 has 1 star, row 2 has 2 stars, and so on!

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

A Bigger Triangle 🔺

Want a taller triangle? Just make the outer loop run more times!

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

Shrinking Triangle 🔻

Flip it! Start the outer loop big and count DOWN to make a shrinking triangle.

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

Heart Triangle 💖

Use any symbol you like! Let us grow a triangle of hearts.

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

Number Triangle 🔢

Fill each row with the row number! A pyramid of numbers. 🔢

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

Counting Triangle 🧮

Fill each row by counting up! Row 3 shows 1 2 3.

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

Christmas Tree 🎄

A triangle of trees looks like a forest growing! 🌲

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

Spaced Triangle ✨

Add a space after each star for a spread-out triangle!

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

Your Turn to Grow 🌟

Change the symbol to a rocket 🚀 or make it 7 rows tall! Edit and run.

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

Quick Check ✅

Triangle brain check! 🧠

Star Triangle Recap 🎉

Your shapes are growing! 🔺 You learned the triangle trick.

  • Inner loop runs c <= r to grow with each row
  • Count outer UP for a growing triangle
  • Count outer DOWN for a shrinking one

Next: printing a real times table! ✖️

Frequently asked questions

Is the “Star Triangles” lesson free?

Yes — the full text of “Star Triangles” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.

What will I learn in “Star Triangles”?

Grow shapes. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Javascript for Kids?

No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Star Triangles” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Javascript for Kids lesson?

Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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