Hollow Pyramid (A..E)

⭐ Pattern Output
Output
A
B B
C C
D D
E E1
Node.js / console version
JavaScript
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 += (i === j ? String.fromCharCode(j) : " ");
for (let k = A + 1; k <= top; k++) line += (i === k ? String.fromCharCode(k) : " ");
console.log(line);
}2Browser version (
Browser version (document.write)
Reference-style output uses for spacing.
HTML
<!DOCTYPE html>
<html>
<body>
<script>
const A = 65;
const last = 69;
for (let i = A; i <= last; i++) {
for (let j = last; j >= A; j--) {
if (i === j) document.write(String.fromCharCode(j));
else document.write(" ");
}
for (let k = A + 1; k <= last; k++) {
if (i === k) document.write(String.fromCharCode(k));
else document.write(" ");
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
1
Core idea
Outer i runs from A to E. First inner loop scans j = E..A and prints the letter when i === j, otherwise prints blanks. Second inner loop scans k = B..E and prints the letter when i === k. Together these form two diagonals that spread outward each row.
Logic
2
Loops + condition
An outer loop picks the row, inner loop(s) decide what to print (letter / star / blank) based on comparisons.
Nested loops
=
Connect it to the output
Compare each loop boundary with the pattern output above — each row corresponds to one outer iteration.
❓ Frequently Asked Questions
They mark the left and right boundary of the hollow pyramid; the spaces between make it hollow.
At the top, both diagonals overlap at the same position, so only
A is printed.HTML collapses spaces, so use
or fixed-width cells to preserve alignment.More JavaScript alphabet patterns
Browse the full list for more variations.
10 people found this page helpful
