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 — Browser)
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 (Browser)</title> </head> <body> <h1>Diamond (document.write)</h1> <p>Edit the loops, then click Run.</p> <script> // Top half for (let i = 1; i <= 5; i++) { for (let j = 1; j < i * 2; j++) { if (j % 2 === 0) document.write("*"); else document.write(String.fromCharCode(i + 64)); } document.write("<br>"); } // Bottom half for (let i = 4; i >= 1; i--) { for (let j = 1; j < i * 2; j++) { if (j % 2 === 0) document.write("*"); else document.write(String.fromCharCode(i + 64)); } document.write("<br>"); } </script> </body> </html>
Lines:
0
| Characters:
0
Live Preview
Auto-refresh on Run