-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (53 loc) · 1.6 KB
/
Copy pathscript.js
File metadata and controls
65 lines (53 loc) · 1.6 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const container = document.querySelector(".container");
let div;
for(let i=0; i<16; i++){
for(let j=0; j<16; j++){
div = document.createElement("div");
div.classList.add("square");
div.style.width= "40px";
div.style.height="40px";
container.appendChild(div);
}
}
const squares = document.querySelectorAll(".square");
squares.forEach((square)=>{
square.addEventListener('mouseover', ()=>{
square.style.backgroundColor = "navy";
square.style.border = "none";
})
})
const button = document.querySelector("button");
button.addEventListener('click', ()=>{
const input = prompt("Please enter a grid number between 1 and 100:", );
if(input === null){
return;
}
const number = parseInt(input, 10);
if(!isNaN(number)){
if(number > 100 || number < 1){
alert("Invalid prompt. Please enter a number between 1 and 100.")
} else {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
for(let i=0; i<number; i++){
for(let j=0; j<number; j++){
const div = document.createElement("div");
div.classList.add("square");
div.style.width= `${640/number}px`;
div.style.height= `${640/number}px`;
container.appendChild(div);
}
}
const squares = document.querySelectorAll(".square");
squares.forEach((square)=>{
square.addEventListener('mouseover', ()=>{
square.style.backgroundColor = "navy";
square.style.border = "none";
})
})
}
} else {
alert("Invalid prompt. Please enter a number.")
}
})