1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| function generateShapes() { let rows = document.getElementById("rows").value; let shapesDiv = document.getElementById("shapes"); shapesDiv.innerHTML = ""; for (let i = 1; i <= rows; i++) { shapesDiv.innerHTML += " ".repeat(rows - i) + "  *".repeat(i) + "<br>"; } shapesDiv.innerHTML += "<br>";
for (let i = 1; i <= rows; i++) { shapesDiv.innerHTML += " ".repeat(rows - i) + "  *".repeat(rows) + "<br>"; } shapesDiv.innerHTML += "<br>";
for (let i = 1; i <= rows; i++) { shapesDiv.innerHTML += "  ".repeat(rows - i) + " *".repeat(i * 2 - 1) + "<br>"; } for (let i = rows - 1; i >= 1; i--) { shapesDiv.innerHTML += "  ".repeat(rows - i) + " *".repeat(i * 2 - 1) + "<br>"; } }
|