-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
72 lines (56 loc) · 1.8 KB
/
scripts.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function getparentnode(){
return document.getElementById("container"); // Use the body tag as the parent node
}
function row(count){
var row = document.createElement("div");
row.style.display = "flex";
row.style.flexDirection = "row";
for(let i = 0; i < count; ++i){
let a = document.createElement("div");
a.style.backgroundColor = "blue";
a.style.border = "1px solid black";
a.style.innterText = "Hello World";
a.style.aspectRatio = "1 / 1";
a.className = "cell";
a.style.flex = "1";
row.appendChild(a);
}
return row;
}
function insertgrid(parentnode, size){
for(let i = 0; i < size; ++i){
let rownode = row(size);
parentnode.appendChild(rownode);
}
}
function deletegrid(parentnode){
while (parentnode.firstChild) {
parentnode.removeChild(parentnode.firstChild);
}
}
let button = document.getElementById("submitButton");
button.addEventListener("click", ()=>{
let inputval = document.getElementById("inputField").value;
console.log(inputval);
if (inputval<1 || inputval >100){
alert("Please enter a number between 1 and 100");
document.getElementById("inputField").value = "";
return;
}
deletegrid(getparentnode());
insertgrid(getparentnode(), inputval);
document.getElementById("inputField").value = "";
document.querySelectorAll(".cell").forEach(cell => {
cell.addEventListener("mouseover", function() {
this.style.backgroundColor = "red";
});
});
});
insertgrid(getparentnode(), 16);
deletegrid(getparentnode());
insertgrid(getparentnode(), 5);
document.querySelectorAll(".cell").forEach(cell => {
cell.addEventListener("mouseover", function() {
this.style.backgroundColor = "red";
});
});