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
- A Loop Inside a Loop
- Rows and Columns
- Star Triangles
- A Times Table