-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
42 lines (32 loc) · 1.2 KB
/
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
function startGame(e) {
let num_boxes = Number(prompt(" Enter number of grid squares (A * A) "));
if (!num_boxes) return console.log("Wrong input"); // type check HERE
console.log(num_boxes);
let boxArray = document.querySelector('#box-array');
if (!(boxArray.hasChildNodes())) { console.log('no child'); }
else {
while (boxArray) {
if (boxArray.firstElementChild) { boxArray.firstElementChild.remove(); }
else break;
}
}
for (let i = 0; i < num_boxes; i++) {
let row = document.createElement('div')
row.id = 'row';
for (let j = 0; j < num_boxes; j++) {
let cell = document.createElement('div');
cell.id = 'cell';
row.appendChild(cell);
}
let row_sel = document.querySelector('#box-array');
console.log(row_sel);
row_sel.appendChild(row);
}
}
function gitLink(e) {
window.open("https://github.com/danielquerrey/DOM-Etch-A-Sketch", "_blank");
}
let gitButton = document.querySelector('#git-btn');
gitButton.addEventListener('click', gitLink);
let startButton = document.querySelector('#header-btn');
startButton.addEventListener('click', startGame);