A repeating alphabet triangle grows by one character each row, but every character on that row is the same letter — the letter advances with the row.
Remember
Rule: for letter i from A to last,
print i with growing width 1, 2, 3, …
A
BB
CCC
DDDD
EEEEE ← 5 rows
Unlike Program 1 (A, AB, ABC), letters do not step across the row — you append the outer loop letter inside the inner loop. The reverse twin is Program 10 (E, DD, CCC, …).
Approach
How to Solve It
Two ways to emit the same shape — start with nested loops, then optionally shorten with String.repeat.
Method
Idea
Best for
Nested loops
Outer = letter; inner = growing width; append outer letter
Learning, interviews, exams
ch.repeat(row)
Build a whole repeated-letter row in one call
Shorter demos once loops click
Pseudocode
Pseudocode
base = code of 'A'
for row from 1 to rows:
ch = fromCharCode(base + row - 1)
line = ""
for j from 1 to row:
append ch to line
print line
Append letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the repeating triangle updates instantly — capped at 26 letters (A–Z).
Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
A
BB
CCC
DDDD
EEEEE
Trace
Worked Walkthrough — rows = 4
Trace each outer-loop letter as the row advances from 1 to 4.
Letter
Inner runs
Printed row
Repeats
A
1
A
1
B
2
BB
2
C
3
CCC
3
D
4
DDDD
4
Total letter prints: 1 + 2 + 3 + 4 = 10 = 4×5/2 — same triangular count as Program 1.
Code
JavaScript Programs
Three complete programs: fixed last letter, prompt input, and a repeat shortcut. Use View Output for sample results, or Try It Yourself to edit and run in the playground.
Example 1 — Fixed rows = 5
Hard-coded height — outer loop picks the letter; inner loop only controls the repeat count.
JavaScript
let rows = 5;
const base = "A".charCodeAt(0);
for (let row = 1; row <= rows; row++) {
const ch = String.fromCharCode(base + row - 1);
let line = "";
for (let j = 1; j <= row; j++) {
line += ch;
}
console.log(line);
}
1. Outer loop picks the row letter. Row 1 → A, row 2 → B, … up through E.
2. Inner loop only counts.j runs from 1 to row, so the width grows 1, 2, 3, …
3. Append ch, not a stepping letter. That keeps every character on the row the same. Stepping codes would rebuild Program 1.
When row = 3 the inner loop runs three times and you get CCC.
Example 2 — User Input Version
Read the row count at runtime with prompt. Validate with parseInt and clamp to 26 for A–Z demos.
JavaScript
let rows = parseInt(prompt("Enter the number of rows:"), 10);
const base = "A".charCodeAt(0);
if (!Number.isFinite(rows) || rows < 1) {
console.log("Please enter a whole number of rows >= 1.");
} else {
if (rows > 26) rows = 26;
for (let row = 1; row <= rows; row++) {
const ch = String.fromCharCode(base + row - 1);
let line = "";
for (let j = 1; j <= row; j++) {
line += ch;
}
console.log(line);
}
}
1. Pick the letter from the row index. Same mapping as Example 2: row 1 → A, row 2 → B, and so on.
2. Fill a string of length row.ch.repeat(row) creates that string — e.g. "C".repeat(3) is CCC.
3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
Wrong letter
Program 1 by mistake
Appending a stepping code instead of the row letter produces A, AB, ABC. Always append the outer-loop letter (ch).
log inside
Column of letters
If console.log is inside the inner loop, each letter lands on its own line. Append with +=; call console.log only after the inner loop.
Off-by-one
Wrong letter mapping
Use base + row - 1. Forgetting - 1 shifts every letter one step forward.
rows > 26
Past Z
Codes leave A–Z when rows > 26. Clamp or reject in interactive programs.
rows = 1
Single A
Output is just A. A good sanity check for the mapping and the break.
Bad prompt
Use Number.isFinite
Bare parseInt(prompt()) yields NaN on letters — validate before the outer loop.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(n) for the current line string
ch.repeat(row) (Example 3)
O(rows²)
O(n) per temporary row string
Total letters = 1 + 2 + … + n = n(n + 1)/2 — quadratic in n. Same totals as Program 1.
Remember
Key Takeaways
Rule: outer loop picks the letter; inner loop only sets how many times to append it.
Append ch, not a stepper: that single choice separates this pattern from Program 1.
Break the row: call console.log only after the inner loop.
Complexity:O(n²) time from the triangular letter count.
One line: for each row letter, append that letter exactly as many times as the row width, then console.log.
Frequently Asked Questions
Because the inner loop appends the outer-loop character every time. The inner counter only controls how many times to append, not which character to print.
Then letters would change across the row (A, AB, ABC…), which is Program 1 — not a repeating-letter triangle.
On the third row the row letter is C, and the inner loop runs three times, appending C each time.
Program 1 prints stepping letters across each row (A, AB, ABC). This pattern keeps one letter per row and only grows the repeat count (A, BB, CCC).
Program 10 uses the same growing widths but letters count downward (E, DD, CCC…). This pattern counts upward (A, BB, CCC…).
line += stays on the same line. console.log ends the current line. Letters use +=; the row break uses console.log after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. console.log(ch.repeat(row)) prints a full repeated-letter row in one call. Nested loops are better for learning; repeat is a handy shortcut later.
🤔
Did you know?
Each row prints the same letter repeatedly: row 1 prints A once, row 2 prints B twice, row 3 prints C three times. Print the outer loop letter inside the inner loop so the row stays uniform. The reverse twin is Program 10.