Step-by-Two Alphabet Rows

What You'll Learn
The inner loop is the same idea as Program 1: for each row, print String.fromCharCode(j) with j from A through the current i. The twist is the outer loop: i jumps by two each time (65, 67, 69, 71, 73), so each row is two letters wider than the previous row’s span requires—giving odd lengths 1, 3, 5, 7, 9.
Total letters: \(1 + 3 + 5 + 7 + 9 = 25\). The reference snippet declared k but never used it; clean code only needs i and j.
⭐ Pattern Output
Five rows with i from 65 to 73, step 2:
A
ABC
ABCDE
ABCDEFG
ABCDEFGHINode.js / console version
Outer loop uses i += 2; upper bound 73 is the last row cap (ASCII for I). You can name the bound outerEnd for clarity:
const start = "A".charCodeAt(0);
const outerEnd = "I".charCodeAt(0); // 73 — last row prints A..I
for (let i = start; i <= outerEnd; i += 2) {
let line = "";
for (let j = start; j <= i; j++) {
line += String.fromCharCode(j);
}
console.log(line);
}Browser version (document.write)
Same logic as the reference: for (i = 65; i <= 74; i += 2) stops after the row with i === 73 because the next i would be 75 > 74:
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 65; i <= 74; i += 2) {
for (let j = 65; j <= i; j++) {
document.write(String.fromCharCode(j));
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: i += 2
i takes values 65, 67, 69, 71, 73 — the last row ends at I.
Inner loop: A to i
for (let j = start; j <= i; j++) prints the forward alphabet from A through the current i.
Line break
After each row, console.log(line) or document.write("<br>").
Odd row lengths
Each row adds two more characters than the previous. Total 25 letters through I. Complexity scales with the sum of row widths.
💡 Tips for Enhancement
Try These
- Compare side by side with Program 1 (
i++vsi += 2) - Try
i += 3and adjust the outer limit to see new width gaps - Use
outerEndas the character code of the last letter you want on the bottom row
Avoid
- Copying the unused
kfrom some older snippets — it is not part of the logic document.writeafter the document has loaded
Key Takeaways
Outer step 2 makes row lengths 1, 3, 5, 7, 9.
Inner loop prints fromCharCode(j) from A to i.
Last row ends at I (code 73).
Total letters printed: 25.
HTML version may use i <= 74 as in the original; effect matches i <= 73 with step 2.
❓ Frequently Asked Questions
i = 73 the next value would be 75, which fails i <= 74, so the loop still runs exactly five times. Using outerEnd = 73 (I) in the Node example states the last row letter directly.i and j. Some tutorials add extra declarations by mistake; you can omit k.Next: JavaScript Alphabet Pattern 15
Mirror bowtie with letters and a growing star band.
The row widths 1, 3, 5, 7, 9 are the first five odd numbers; their sum is a perfect square: 5² = 25.
10 people found this page helpful
