Inverted Triangle Alphabet Pattern in JavaScript

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Descending loops

What You'll Learn

The outer loop moves the “start” of each row from E down to A. The inner loop prints from E down to that letter, so rows grow longer as you go down—the mirror of Program 1’s shape.

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

⭐ Pattern Output

When you run the program for five rows (from E down to A):

Output
E
ED
EDC
EDCB
EDCBA
1

Node.js / console version

Uses let, builds each row in a string, and prints with 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 = end; j >= i; j--) {
    line += String.fromCharCode(j);
  }
  console.log(line);
}
2

Browser version (document.write)

Classic tutorial style: write into the document as the page loads. Save as .html and open in a browser, or use the live editor:

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

🧠 How It Works

1

Outer loop: row anchor

for (let i = end; i >= start; i--) picks the smallest letter printed on the current row (from E down to A).

Descending i
2

Inner loop: print the suffix

for (let j = end; j >= i; j--) prints letters from E down to i, which matches the reference pattern.

Descending j
3

New line after each row

Use console.log(line) in Node, or document.write("<br>") in HTML.

Line break
=

Inverted rows

Same total work as Program 1: O(n²) character writes for n rows. Each row is a reverse run from E to the current i.

💡 Tips for Enhancement

Try These

  • Swap start and end to change how many rows you print
  • Compare with inverted star triangle (same loop idea)
  • Build the row with Array.from and .join("") for a functional style

Avoid

  • Using document.write after the document has finished loading
  • Off-by-one mistakes on the inner bound (j >= i)

Key Takeaways

1

Both loops move downward in letter value; each row is a suffix E..i.

2

69 is 'E', 65 is 'A' in ASCII.

3

Total letters: \(n(n+1)/2\) for n rows.

4

This is the letter version of an inverted right triangle.

5

Time complexity: O(n²).

❓ Frequently Asked Questions

Program 1 grows rows from A upward. Program 2 fixes the high letter at E and extends leftward each row by lowering the minimum letter from E to A.
Yes. You can slice "EDCBA" or build substrings, but numeric codes match the classic nested-loop teaching style.
Still O(n²) for n rows: the inner loop length increases each time.

Next: JavaScript Alphabet Pattern 3

Continue to the next program in the alphabet pattern series.

Program 3 →
Did you know?

Decrementing j from end to i is the same structure as counting stars in an inverted triangle—only the character source changes.

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