Suffix-to-E Rows in JavaScript

What You'll Learn
The first row is the full run A–E. Each following row drops the leftmost letter: BCDE, CDE, DE, then E. The outer loop picks the starting letter; the inner loop always runs from that letter up to E.
Total letters printed is \(5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2\) for five rows.
⭐ Pattern Output
Five rows as i moves from A to E:
ABCDE
BCDE
CDE
DE
ENode.js / console version
Outer loop increases i from start to end; inner loop runs j from i to end:
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);
for (let i = start; i <= end; i++) {
let line = "";
for (let j = i; j <= end; j++) {
line += String.fromCharCode(j);
}
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 = 65; i <= 69; i++) {
for (let j = i; j <= 69; j++) {
document.write(String.fromCharCode(j));
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: row start letter
for (let i = start; i <= end; i++) sets the first character of each row: A, then B, …, finally E.
iInner loop: through E
for (let j = i; j <= end; j++) prints forward from i to the fixed end E.
i..ELine break
After each row, console.log(line) or document.write("<br>").
Program 3, reversed order
Same inner structure as Program 3, but the outer loop direction flips which row appears first. Complexity O(n²).
💡 Tips for Enhancement
Try These
Avoid
- Starting the inner loop at
Aevery time (that is Program 1’s growing triangle, not this pattern) document.writeafter the document has loaded
Key Takeaways
Outer loop: A → E; inner loop: i → E.
Each row is a suffix of ABCDE.
Total letters: \(n(n+1)/2\).
Row order is the reverse of Program 3 for the same range.
Time complexity: O(n²).
❓ Frequently Asked Questions
j from i to E). Program 3 decrements i from E to A, so the single-letter row prints first. Program 6 increments i, so ABCDE prints first.A and shortens the right end. Program 6 moves the left start rightward while keeping E on the right.n rows from A to E.Next: JavaScript Alphabet Pattern 7
Continue to the next program in the alphabet pattern series.
If you reverse the order of the rows printed here, you get the same lines as Program 3 for A–E.
10 people found this page helpful
