Descending Repeat Rows

What You'll Learn
Like Program 9, each row repeats a single letter and row lengths are 1, 2, …, 5. Here i counts down from E to A, and the inner loop runs j from end down to i so there are end - i + 1 copies of String.fromCharCode(i).
Total characters: \(1 + 2 + 3 + 4 + 5 = 15 = n(n+1)/2\) for five rows.
⭐ Pattern Output
Five rows from E down to A:
E
DD
CCC
BBBB
AAAAANode.js / console version
Outer loop decreases i from end to start; inner loop runs j from end down to i, printing fromCharCode(i) each time:
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);
for (let i = end; i >= start; i--) {
let line = "";
for (let j = end; j >= i; j--) {
line += String.fromCharCode(i);
}
console.log(line);
}Browser version (document.write)
Same logic with ASCII codes 65–69. Save as .html or use the live editor:
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 69; i >= 65; i--) {
for (let j = 69; j >= i; j--) {
document.write(String.fromCharCode(i));
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: row letter
for (let i = end; i >= start; i--) walks from E down to A. That letter is repeated for the whole row.
iInner loop: repeat count
for (let j = end; j >= i; j--) runs end - i + 1 times. The body always appends String.fromCharCode(i).
Line break
After the inner loop, console.log(line) or document.write("<br>").
Same lengths as Program 9
Both use row lengths 1, 2, …, n. Program 9 assigns the k-th row to the k-th letter from A; Program 10 assigns it to the k-th letter counting down from E. Complexity O(n²).
💡 Tips for Enhancement
Try These
Avoid
- Printing
fromCharCode(j)here — that becomes Program 2’s triangle, not repeated letters document.writeafter the document has loaded
Key Takeaways
Outer i: E → A; inner j: E → i (descending).
Each row repeats one letter; lengths are 1, 2, 3, 4, 5.
Total characters: \(n(n+1)/2\).
Same row lengths as Program 9; letters run E → A instead of A → E.
Time complexity: O(n²).
❓ Frequently Asked Questions
String.fromCharCode(i) per row with lengths 1 … n. Program 9 uses outer i ascending and inner j from start to i; Program 10 uses outer i descending and inner j from end to i. The first row is A vs E.j from E down to i, outer i from E down to A). Program 2 uses fromCharCode(j) so each position shows a different letter; Program 10 uses fromCharCode(i) so the row is uniform.n rows from A to E.Next: JavaScript Alphabet Pattern 11
Continue to the next program in the alphabet pattern series.
Program 9 uses i from A up and j from start to i; Program 10 uses i from E down and j from end to i—both repeat fromCharCode(i) for the same row lengths.
10 people found this page helpful
