Mirror Bowtie Letters & Stars

What You'll Learn
This pattern prints a symmetric line for each row: ascending letters from A to the current i, a middle section of stars that grows as i shrinks, then descending letters from i back to A. The outer loop counts i down from E (69) to A (65).
On the top row (i === E) there is no middle gap. Each step down adds two more stars because the middle loop runs once more and emits two * characters per iteration (matching the original two <div>*</div> writes).
⭐ Pattern Output
Console-style view (stars shown as *):
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********ANode.js / console version
Build each row as a string. Let top = 'E'.charCodeAt(0) (69). Middle stars: 2 × (top - i) characters.
const A = "A".charCodeAt(0);
const top = "E".charCodeAt(0); // 69
for (let i = top; i >= A; i--) {
let line = "";
for (let j = A; j <= i; j++) line += String.fromCharCode(j);
for (let k = i; k < top; k++) line += "**";
for (let m = i; m >= A; m--) line += String.fromCharCode(m);
console.log(line);
}Browser version (document.write + div)
Same logic as the reference: each character lives in a fixed-width div so columns line up. The middle loop writes two star divs per k. Use let for m (some older snippets forgot to declare m).
<!DOCTYPE html>
<html>
<head>
<style>
div {
display: inline-block;
text-align: center;
width: 13px;
}
</style>
</head>
<body>
<script>
const A = 65;
const top = 69;
for (let i = top; i >= A; i--) {
for (let j = A; j <= i; j++) {
document.write("<div>" + String.fromCharCode(j) + "</div>");
}
for (let k = i; k < top; k++) {
document.write("<div>*</div><div>*</div>");
}
for (let m = i; m >= A; m--) {
document.write("<div>" + String.fromCharCode(m) + "</div>");
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: i from E to A
Each row uses a shorter prefix and suffix while the middle grows.
Left wing: j from A to i
String.fromCharCode(j) prints the ascending half.
Middle: k from i to 68
Loop condition k < 69 (E). Each pass adds two * symbols.
Right wing: m from i to A
Mirrors the left side so the row reads the same forwards and backwards around the stars.
Palindrome layout
Letter counts shrink by one per row; star count steps by two.
💡 Tips for Enhancement
Try These
- Swap
*for another character or use a single widerdivper star pair - Change
topto another letter code to resize the pattern - Compare with Program 5 (plain decreasing letter rows)
Avoid
- Initializing
kto65before the middle loop — it is overwritten and confuses readers - Leaving
mundeclared (implicit global in sloppy mode)
Key Takeaways
Three inner loops per row: ascending letters, stars, descending letters.
Star run length is 2 × (69 - i) characters in the console version.
div layout keeps monospace alignment in the browser.
Total letter characters printed: 30 (twice the \(5 + 4 + 3 + 2 + 1\) letter triangle).
❓ Frequently Asked Questions
69 is 'E'. Values k = i, i+1, …, 68 give (69 - i) iterations. Multiplying by two stars per iteration matches the widening ** block in the sample output.for loop assigns k = i immediately. A separate initializer at 65 is a common copy-paste mistake from other programs.A..i concatenated with i..A. The stars sit on the axis of symmetry.Next: JavaScript Alphabet Pattern 16
Wide pyramid with padding and a single letter counter.
The star counts per row 0, 2, 4, 6, 8 are an arithmetic sequence; their sum is 20 star characters across all rows.
10 people found this page helpful
