CodeToFun
Learn Programming Free
Tutorials
Languages
Features
About
Sign In
Tutorials
Languages
Features
About
Sign In
Back
/
JavaScript Alphabet Pattern 21
JavaScript Alphabet Pattern 21 (Try It)
Try It
Run
Reset
Save
Save to Google Drive
Sync with your Google account
Download HTML
Save to your device
Share
Full
HTML Code
Copy
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Alphabet Pattern 21 - Try It</title> </head> <body> <h1>Alphabet diamond with stars</h1> <p>Edit <code>top</code> or replace <code>*</code>, then click Run.</p> <pre id="output"></pre> <script> (() => { const top = 5; let result = ""; for (let i = 1; i <= top; i++) { let line = ""; for (let j = 1; j < i * 2; j++) { line += j % 2 === 0 ? "*" : String.fromCharCode(i + 64); } result += line + "\n"; } for (let i = top - 1; i >= 1; i--) { let line = ""; for (let j = 1; j < i * 2; j++) { line += j % 2 === 0 ? "*" : String.fromCharCode(i + 64); } result += line + "\n"; } document.getElementById("output").textContent = result; })(); </script> </body> </html>
Lines:
0
| Characters:
0
Live Preview
Auto-refresh on Run