CodeToFun
Learn Programming Free
Tutorials
Languages
Features
About
Sign In
Tutorials
Languages
Features
About
Sign In
Back
/
JavaScript Star Pattern 10
JavaScript Star Pattern 10 (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 Star Pattern 10 - Try It</title> </head> <body> <h1>Filled Diamond Star Pattern</h1> <p>Open the HTML code and change <code>rows</code>, then click Run.</p> <pre id="output"></pre> <script> (() => { // Change this value to try different sizes const rows = 5; function buildRow(i, rows) { return " ".repeat(rows - i) + "*".repeat(2 * i - 1); } let result = ""; for (let i = 1; i <= rows; i++) result += buildRow(i, rows) + "\n"; for (let i = rows - 1; i >= 1; i--) result += buildRow(i, rows) + "\n"; document.getElementById("output").textContent = result; })(); </script> </body> </html>
Lines:
0
| Characters:
0
Live Preview
Auto-refresh on Run