CodeToFun
Learn Programming Free
Tutorials
Languages
Features
About
Sign In
Tutorials
Languages
Features
About
Sign In
Back
/
JavaScript Number Pattern 41
JavaScript Number Pattern 41 (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 Number Pattern 41 - Try It</title> </head> <body> <h1>Centered Square Number Pyramid</h1> <p>Edit the max width and click Run.</p> <pre id="output"></pre> <script> let m = 1; let result = ""; const maxWidth = 9; // odd widths: 1,3,5,7,9 for (let count = 1; count <= maxWidth; count += 2) { let line = ""; for (let s = count; s < maxWidth; s++) { line += " "; } for (let k = 1; k <= count; k++) { line += String(m * m).padStart(3, " ") + " "; m++; } result += line.trimEnd() + "\n"; } document.getElementById("output").textContent = result; </script> </body> </html>
Lines:
0
| Characters:
0
Live Preview
Auto-refresh on Run