-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.13 KB
/
Copy pathscript.js
File metadata and controls
44 lines (37 loc) · 1.13 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
const container = document.getElementById('container');
gridMaker(container, 16);
function gridMaker(container, numPerSide){
container.style.gridTemplateColumns = `repeat(${numPerSide}, 1fr)`;
let boxes = [];
numPerSide = numPerSide * numPerSide;
for(i=0;i<numPerSide;i++){
let div = document.createElement('div');
div.id = "d"+i;
div.className = 'eas-boxes'
boxes[i] = div;
container.appendChild(boxes[i]);
boxes[i].addEventListener("mouseover", function(e){
e.target.style.backgroundColor = "crimson";
});
}
}
function removeAllChildNodes(parent) {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}
const resetButton = document.getElementById('reset');
resetButton.addEventListener('click',function(){
removeAllChildNodes(container);
function number(){
//fix decimal catching
let num = parseInt(prompt('Please enter desired squares per side of the etch-a-sketch.'));
if((num > 0) && (num < 101) && (num%1)==0)
return num;
else{
alert('unexpected input, try again');
return number();
}
}
gridMaker(container, number())
})