1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| const generateBoxes = (limit, parent) => { const colors = [ "#577590", "#43aa8b", "#90be6d", "#f9c74f", "#f8961e", "#f3722c", "#f94144", ]; for (let i = 0; i < limit; i += 1) { const box = document.createElement("div"); box.classList.add("box"); box.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)]; box.style.height = `${Math.floor(Math.random() * 300 + 50)}px`; box.style.width = `${Math.floor(Math.random() * 300 + 50)}px`; box.style.top = `${Math.floor(Math.random() * 100)}%`; box.style.left = `${Math.floor(Math.random() * 100)}%`; parent.appendChild(box); } };
|