Alphabet Diamond (A to E)

⭐ Pattern Output
Output
A
B B
C C
D D
E E
D D
C C
B B
A1
Node.js / console version
JavaScript
const A = "A".charCodeAt(0);
const top = "E".charCodeAt(0);
function printRow(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);
}
for (let i = A; i <= top; i++) printRow(i);
for (let i = top - 1; i >= A; i--) printRow(i);2Browser version (
Browser version (document.write)
Reference-style output uses for spacing.
HTML
<!DOCTYPE html>
<html>
<body>
<script>
const A = 65;
const last = 69;
function printRow(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>");
}
for (let i = A; i <= last; i++) printRow(i);
for (let i = last - 1; i >= A; i--) printRow(i);
</script>
</body>
</html>🧠 How It Works
1
Core idea
This is Program 33 (top half) plus a mirrored bottom half. First part prints rows for i = A..E; second part prints rows for i = D..A. Each row is built with two scans so the letter appears at two diagonal positions, forming a diamond outline.
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
The first part builds the diamond from
A up to E; the second part mirrors it back down to A.At
i = E, the diagonals are farthest apart, creating the widest part of the diamond outline.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
