Shape Rule
One letter, growing count
Row 1 prints A, row 2 prints BB, row 3 prints CCC, row 4 prints DDDD, row 5 prints EEEEE.

Row 1 is one A, row 2 is two Bs, row 3 three Cs, and so on: A, BB, CCC, DDDD, EEEEE. Contrast Program 1, where letters change inside each row. Here, the row letter stays the same and only the count grows. Next up: Program 10 reverses the letter order. Includes a live preview, worked JavaScript examples, edge cases, and complexity.
One letter, growing count
Row 1 prints A, row 2 prints BB, row 3 prints CCC, row 4 prints DDDD, row 5 prints EEEEE.
Row letter
for (let row = 1; row <= rows; row++) picks both the letter offset and how many times to repeat it on each line.
Count only
for (let j = 0; j < row; j++) { line += ch; } appends the same letter row times — the inner loop only controls count, not which letter.
ch.repeat(row)
console.log(ch.repeat(row)) repeats the letter in one line — same output as nested loops.
Rows 1–26
Pick a row count and draw A, BB, CCC live.
Complexity
1+2+…+n printed characters total.
A repeating-letter alphabet pattern (A, BB, CCC, ...) prints one letter per row, repeated as many times as the row number. With five rows the console shows A, BB, CCC, DDDD, EEEEE — unlike Program 1, where letters change inside each row.
in JavaScript you solve it with two nested for loops: compute ch = String.fromCharCode("A".charCodeAt(0) + row - 1), repeat that letter row times with the inner loop, then call console.log(line) for the next line. Or shorten each row to console.log(ch.repeat(row)).
It teaches that the inner loop can control repetition count while the outer loop picks the value — a key idea before Program 10’s reverse variant.
ch = String.fromCharCode("A".charCodeAt(0) + row - 1)
for (let j = 0; j < row; j++) — count only.
line += ch then console.log(line).
A, BB, CCC, …
In short: for each row from 1 to rows, set ch = String.fromCharCode("A".charCodeAt(0) + row - 1), append ch exactly row times with line += ch, then call console.log(line).
Given a positive integer rows, print a left-aligned repeating-letter alphabet pattern: each row prints one letter repeated row times (A, BB, CCC when rows = 5).
// First 5 rows (conceptual shape)
// A
// BB
// CCC
// DDDD
// EEEEE | Item | Type | Description |
|---|---|---|
rows / top | int / char | Number of rows; last letter is 'A' + rows - 1 (E for 5). |
| Printed output | text | Growing rows of repeated letters A, BB, CCC, … |
base = "A".charCodeAt(0)
for row from 1 to rows:
ch = String.fromCharCode(base + row - 1)
repeat ch exactly row times (inner loop or ch.repeat(row))
console.log(line) | Approach | Idea | Best for |
|---|---|---|
| Char nested loops | Outer i++, inner count, print i | Matching this classic sample |
| Row index + char math | ch = (char)('A' + row - 1) then print row times | User-input versions; clearer count |
| Goal | Pattern |
|---|---|
| Walk each row | for (let row = 1; row <= rows; row++): |
| Row letter | ch = String.fromCharCode("A".charCodeAt(0) + row - 1) |
| Repeat letter | for (let j = 0; j < row; j++) { line += ch; } |
| End the row | console.log(line) |
| One-line shortcut | console.log(ch.repeat(row)) |
| Stepping letters variant | See Program 1 — A, AB, ABC triangle |
| Reverse repeat variant | See Program 10 (E, DD, CCC, …) |
ch.repeat(row)Same A, BB, CCC shape — two ways to think about row letter and repetition count.
for (let j = 0; j < row; j++)Classic charCode loop — teaches letter formula and repetition count separately
console.log(ch.repeat(row))String.repeat — compact one-liner per row
loops firstMaster nested loops before the string shortcut
Reach for this when teaching that the inner loop can control count while the outer variable controls the printed value.
Keep the same loop bounds; change only line += String.fromCharCode(j) to line += String.fromCharCode(i).
Practice decoupling “what to print” from “how many times.”
Next keeps repeats but walks the letter backward: E, DD, CCC.
Map row numbers to letters with 'A' + row - 1.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: printing the outer letter inside the inner loop is the cleanest way to build a growing triangle of repeated characters.
Choose 1–26 rows and draw the repeating-letter alphabet triangle in the browser.
Three complete JavaScript programs — fixed A–E, user-chosen row count, and a ch.repeat(row) shortcut. Click View Output to reveal sample console results, or Try it Yourself to run in the browser editor.
Print five growing rows of repeated letters from A to E.
rows = 5Hard-coded height — ideal for first demos and screenshots.
const 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 = 0; j < row; j++) {
line += ch;
}
console.log(line);
} When row = 1, ch is A and the inner loop appends it once. When row = 3, ch is C and the line becomes CCC. When row = 5, ch is E and the row is EEEEE. console.log(line) after the inner loop starts the next row.
Let the user choose how many rows to print.
Read the row count with prompt() and convert with parseInt() (validate with Number.isFinite in real apps).
const rowsInput = prompt("Enter the number of rows (max 26):");
let rows = parseInt(rowsInput, 10);
rows = Math.max(1, Math.min(rows, 26));
const base = "A".charCodeAt(0);
for (let row = 1; row <= rows; row++) {
const ch = String.fromCharCode(base + (row - 1));
let line = "";
for (let j = 0; j < row; j++) {
line += ch;
}
console.log(line);
} For row 4, ch becomes D and the inner loop appends it four times. Cap rows at 26 so ch stays within A–Z.
Same shape with JavaScript String.repeat.
ch.repeat(row) String RepetitionRepeat the row letter by the row number — same triangle, one log per row.
const rows = 5;
const clampedRows = Math.max(1, Math.min(rows, 26));
const base = "A".charCodeAt(0);
for (let row = 1; row <= clampedRows; row++) {
const ch = String.fromCharCode(base + (row - 1));
console.log(ch.repeat(row));
} String.fromCharCode("A".charCodeAt(0) + row - 1).repeat(row) builds each line in one expression. Keep the nested-loop version for exams that ask you to show outer vs inner letter logic.
i runs from 'A' to top. That’s the character printed on the row.
j runs from 'A' to i, so it executes 1, 2, 3, … times as rows grow.
Appending ch (the row letter) keeps the whole row the same. Appending the inner counter would change letters across the row (Program 1).
console.log(line) ends each row before the next letter begins.
Total prints are 1+2+…+n for n rows, so time complexity is O(n²).
rows = 5Trace each outer-loop row value and see how the letter formula and repetition count produce each printed line.
row | Letter | Count | Output |
|---|---|---|---|
1 | A | 1 | A |
2 | B | 2 | BB |
3 | C | 3 | CCC |
4 | D | 4 | DDDD |
5 | E | 5 | EEEEE |
Highlight rows 1, 3, and 5: A ×1 → A; C ×3 → CCC; E ×5 → EEEEE. Total letter prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.
Where this repeating-letter alphabet triangle shows up beyond the homework prompt.
Clearest demo of printing the outer variable inside the inner loop.
Example: change line += String.fromCharCode(i) to line += String.fromCharCode(j) and compare with Program 1.
Build intuition for loops that only control iteration count.
Example: rewrite the inner loop as for (int k = 0; k < n; k++).
Map row indexes to letters with 'A' + row - 1.
Example: scale from 5 to 8 without rewriting loops.
Later rewrite as new string(ch, row) once the idea clicks.
Example: same output with one print per row.
Triangle sums make O(n²) easy to see.
Example: 15 letters for 5 rows.
Sits between Programs 8 and 10 in the alphabet set.
Example: revisit Program 1.
Pro Tip: say “pick the letter outside, repeat it inside” before coding — that story prevents printing j by habit.
Why this pattern earns a spot early in the alphabet-pattern series.
A stepping-letter row (ABC) shows immediately if you printed j.
Only the printed variable changes.
Change the top letter or row count and the whole triangle grows.
No padding or diagonal checks — just two loops and one print rule.
Pro Tip: master Program 1 first; this page is mostly “same loops, print the outer letter.”
Small habits that keep repeating-letter alphabet triangles clean.
Printing j turns this into Program 1.
Do not increment the character inside the inner loop.
Keep the row letter inside A–Z when taking user input.
Validate the row count before using parseInt(prompt()).
Use ch = (char)('A' + row - 1) when working with integer row indexes.
Pro Tip: if you see A, AB, ABC, you appended j — switch back to appending the row letter ch (or i).
Mistakes that commonly break repeating-letter alphabet triangles.
Using String.fromCharCode(base + row) skips A on row 1 or starts at B. Forgetting row - 1 shifts every letter forward.
→ Always use ch = String.fromCharCode(base + (row - 1)) with 1-based row values.
A 0-based outer loop breaks String.fromCharCode(base + row - 1) unless you add extra +1 fixes — start at 1 so row matches both letter offset and repeat count.
→ Use for (let row = 1; row <= rows; row++): so row matches both letter offset and repeat count.
Row 27 would need a letter beyond Z — String.fromCharCode() still returns a character but not the expected alphabet pattern.
→ Clamp with rows = Math.max(1, Math.min(rows, 26)) after reading input.
Printing a changing letter inside the inner loop produces A, AB, ABC — Program 1, not this pattern.
→ Print the same ch every time in the inner loop, or use console.log(ch.repeat(row)).
Omitting console.log(line) glues every letter onto one endless line.
→ Always end the row after the inner loop (unless using console.log(ch.repeat(row)) alone).
Check these inputs before calling the solution done.
Output is just A.
A through EEEEE (Example 1).
Ends at DDDD (Example 2).
Cap or reject — the row letter leaves the alphabet.
Validate with Number.isFinite validation.
Swap 'A' for 'a' as the base.
Try these variations to lock in the pattern.
line += String.fromCharCode(i) to line += String.fromCharCode(j)new string(ch, row)i (not j) is what keeps each row uniform.Quick Takeaway: choose the row letter in the outer loop, then print that letter once per inner iteration — that alone builds A, BB, CCC, …
| Program | Time | Extra space |
|---|---|---|
| Inline / input (Examples 1–2) | O(n²) | O(1) |
ch.repeat(row) (Example 3) | O(n²) | O(1) |
For n rows you print 1+2+…+n = n(n+1)/2 characters, so total work is O(n²).
The repeating-letter alphabet triangle is Program 1 with a different print rule: the outer loop picks the letter, and the inner loop only repeats it. Master the classic A…EEEEE sample, then try user input and the multiplication shortcut.
Practice the three examples above, then continue to Alphabet Pattern 10.
Outer row letter from "A".charCodeAt(0) to top; inner loop counts repeats; append ch each time, then console.log(line) for the newline.
i or ch) inside the inner loopch = (char)('A' + row - 1) for integer row indexesj when you want A, BB, CCC- 1 in the letter formulaconsole.log(line) inside the letter loopPrint the repeating-letter alphabet triangle the beginner-friendly way.
One letter, growing repeats
Definitionline += ch (row letter), not j
CodeControls count only
ShapeSame loops, different print
CompareO(n²) time
AnalysisEach row logs one letter repeated row times: row 1 is A, row 2 is BB, row 3 is CCC. Letter = String.fromCharCode("A".charCodeAt(0) + row - 1). Compare Program 10 (reverse repeated letters) and Program 1 (classic A.. triangle).
Reverse repeating triangle — the next alphabet pattern in the series.
12 people found this page helpful