Right-aligned Descending Letters

What You'll Learn
This pattern prints a right-aligned pyramid using descending letters per row. We scan from E down to A each time: if the current letter is “past” the row letter, we print a blank; otherwise we print the character.
⭐ Pattern Output
A
BA
CBA
DCBA
EDCBANode.js / console version
Build each row as a string with leading spaces, then print it.
const A = "A".charCodeAt(0);
const top = "E".charCodeAt(0);
for (let i = A; i <= top; i++) {
let line = "";
for (let j = top; j >= A; j--) {
line += j > i ? " " : String.fromCharCode(j);
}
console.log(line);
}Browser version (document.write + div)
Use fixed-width cells so blanks don’t collapse.
<!DOCTYPE html>
<html>
<head>
<style>
div.cell {
display: inline-block;
text-align: center;
width: 13px;
}
</style>
</head>
<body>
<script>
const A = 65;
const top = 69;
for (let i = A; i <= top; i++) {
for (let j = top; j >= A; j--) {
if (j > i) document.write(\"<div class=\\\"cell\\\"></div>\");
else document.write(\"<div class=\\\"cell\\\">\" + String.fromCharCode(j) + \"</div>\");
}
document.write(\"<br>\");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: i from A to E
As i increases, one more letter becomes visible on the left.
Inner loop: j from E to A
Each row scans five positions in reverse order (E..A).
j > i prints blanks
Before the diagonal, print spaces (or empty cells) to right-align the letters.
Right-aligned triangle
Rows gradually fill from the rightmost A towards the leftmost E.
Key Takeaways
Scan letters in reverse (E..A) for each row.
Use a blank when j > i to right-align.
Fixed-width cells keep the browser output aligned.
Time complexity: O(n²).
❓ Frequently Asked Questions
top (for example to "J".charCodeAt(0) or 74) and the loops will scale automatically. or fixed-width cells to preserve alignment.Keep going
Try the next alphabet program or browse the full list.
If you replace blanks with *, you’ll get an easy visual debug of alignment while building patterns.
10 people found this page helpful
