Suffix-to-E Alphabet Rows in JavaScript

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Mixed loop directions

What You'll Learn

The outer index moves from E down to A. On each row, the inner loop prints forward from that letter through E. Row one is just E; the last row is the full AE run.

Total letters printed is still \(1 + 2 + \cdots + n = \frac{n(n+1)}{2}\) for n rows.

⭐ Pattern Output

For five rows (E down to A):

Output
E
DE
CDE
BCDE
ABCDE
1

Node.js / console version

Build each row with an inner loop from i to end, then console.log:

JavaScript
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);

for (let i = end; i >= start; i--) {
  let line = "";
  for (let j = i; j <= end; j++) {
    line += String.fromCharCode(j);
  }
  console.log(line);
}
2

Browser version (document.write)

Classic HTML page that writes as it parses. Save as .html or open in the live editor:

HTML
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 69; i >= 65; i--) {
  for (let j = i; j <= 69; j++) {
    document.write(String.fromCharCode(j));
  }
  document.write("<br>");
}
</script>
</body>
</html>

🧠 How It Works

1

Outer loop: move the left edge

for (let i = end; i >= start; i--) sets the first character of the row: E, then D, …, down to A.

Descending i
2

Inner loop: print through E

for (let j = i; j <= end; j++) walks codes upward so the row reads left-to-right along the alphabet until E.

Ascending j
3

Line break

After the inner loop finishes one row, use console.log or document.write("<br>").

New row
=

Growing forward runs

Each row is one character longer than the previous. Work is O(n²) for n rows, same total letters as Programs 1 and 2.

💡 Tips for Enhancement

Try These

  • Compare with right-aligned star triangle (similar “widening” idea)
  • Print the same pattern using String.slice on "ABCDE"
  • Change end to another letter and watch the row widths adjust

Avoid

  • Swapping inner bounds by mistake (j must run up to end)
  • Using document.write after load in production pages

Key Takeaways

1

Outer loop decreases; inner loop increases—classic mixed-direction nested loops.

2

Row i prints characters with codes i … end.

3

Total output length: \(n(n+1)/2\) letters.

4

Contrasts with Program 2, which prints backward from E to i.

5

Time complexity: O(n²).

❓ Frequently Asked Questions

That is the first letter of the row. The inner loop then continues to E, so you get DE when i is D, and so on.
Same row lengths (1, 2, 3, …), but Program 1 always starts at A on the left. Here the left edge moves while the right edge stays at E.
O(n²) for n rows between A and E.

Next: JavaScript Alphabet Pattern 4

Continue to the next program in the alphabet pattern series.

Program 4 →
Did you know?

If you reverse each row string, you get the rows of Program 2 for the same AE range—same loops, different print order.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful