-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (30 loc) · 869 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
const grid = document.querySelector('.container');
const btn = document.querySelector('#btn');
const hover = document.querySelector('.container');
let size = makeGrid(16);
function makeGrid(size){
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const sqr = document.createElement('div');
sqr.classList.add("square");
grid.appendChild(sqr);
}
}
}
function newGrid(size){
grid.innerHTML='';
const squareSize = document.querySelector(':root');
squareSize.style.setProperty('--size', `${size}`);
makeGrid(size);
}
hover.addEventListener("mouseover", (event) => {
event.target.style.background = "red";
});
btn.addEventListener('click', () => {
size = prompt('Give the size of the grid (MAX 100)');
if(size === null || size >= 100 || size == 0){
alert("Size not valid, enter a number again");
}else{
newGrid(size);
}
})