-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (27 loc) · 914 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const container = document.querySelector(".container");
const button = document.querySelector("button");
function makeGrid(rows, cols) {
container.style.setProperty("--grid-rows", rows);
container.style.setProperty("--grid-cols", cols);
for(let i = 0; i < (rows * cols); i++) {
let cell = document.createElement("div");
container.appendChild(cell).className = "grid-item";
}
}
makeGrid(16, 16);
button.addEventListener("click", () => {
let size = parseInt(prompt("Choose the grid size, maximum 100"));
if (size > 100) {
alert("Higher than 100 try a smaller number");
} else if (size < 0) {
alert("Grid too small");
} else {
document.querySelectorAll(".grid-item").forEach(e => e.remove());
makeGrid(size, size);
}
});
container.addEventListener("mouseover", (e) => {
if (e.target.className === "grid-item") {
e.target.style.backgroundColor = "black";
}
})