-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
45 lines (31 loc) · 1001 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
35
36
37
38
39
40
41
42
43
44
45
const container = document.querySelector("#container");
function gridEventListener() {
const grid = document.getElementsByClassName("grid-cell");
Array.from(grid).forEach((e) => {
e.addEventListener("mouseover", () => {
e.classList.add("colored");
});
});
}
function makeGrid(a=16) {
for(var x = 0; x < a; x++) {
const gridRow = document.createElement("div");
gridRow.setAttribute("class", "grid-row");
for(var y = 0; y < a; y++) {
const gridCell = document.createElement("div");
gridCell.setAttribute("class", "grid-cell");
gridRow.appendChild(gridCell);
}
container.appendChild(gridRow);
}
}
makeGrid();
gridEventListener();
const resetButton = document.querySelector("#reset");
resetButton.onclick = function() {
var newGridSize = prompt("Enter a grid size please (up to 100 for a 100x100 grid, else it lags)");
container.textContent = "";
makeGrid(newGridSize);
const grid = document.getElementsByClassName("grid-cell");
gridEventListener();
};