Mirror Bowtie Letters & Stars

Beginner
⏱️ 10 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
i from EA

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 *):

Output
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A
1

Node.js / console version

Build each row as a string. Let top = 'E'.charCodeAt(0) (69). Middle stars: 2 × (top - i) characters.

JavaScript
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);
}
2

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).

HTML
<!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

1

Outer loop: i from E to A

Each row uses a shorter prefix and suffix while the middle grows.

5 rows
2

Left wing: j from A to i

String.fromCharCode(j) prints the ascending half.

Forward
3

Middle: k from i to 68

Loop condition k < 69 (E). Each pass adds two * symbols.

Stars
4

Right wing: m from i to A

Mirrors the left side so the row reads the same forwards and backwards around the stars.

Reverse
=

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 wider div per star pair
  • Change top to another letter code to resize the pattern
  • Compare with Program 5 (plain decreasing letter rows)

Avoid

  • Initializing k to 65 before the middle loop — it is overwritten and confuses readers
  • Leaving m undeclared (implicit global in sloppy mode)

Key Takeaways

1

Three inner loops per row: ascending letters, stars, descending letters.

2

Star run length is 2 × (69 - i) characters in the console version.

3

div layout keeps monospace alignment in the browser.

4

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.
No. The middle for loop assigns k = i immediately. A separate initializer at 65 is a common copy-paste mistake from other programs.
If you remove the stars, each row is a palindrome built from 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.

Program 16 →
Did you know?

The star counts per row 0, 2, 4, 6, 8 are an arithmetic sequence; their sum is 20 star characters across all rows.

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