-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
52 lines (47 loc) · 1.56 KB
/
action.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
const container = document.getElementById("container");
let rows = document.getElementsByClassName("gridRow");
let cells = document.getElementsByClassName("cell")
let btn = document.getElementById("btn")
let reload = document.getElementById('reload')
//reset screen
reload.addEventListener('click', deleteContent);
//Start game
btn.addEventListener('click', play);
function makeRow(number) {
for (k = 0; k < number; k++) {
let row = document.createElement("div");
container.appendChild(row).className = "gridRow";
}
}
function makeColumn(number) {
for (i = 0; i < rows.length; i++) {
for (j = 0; j < number; j++) {
let newCell = document.createElement("div");
rows[j].appendChild(newCell).className = "cell";
//Add action to change color on mouse over
newCell.setAttribute('onMouseOver', 'style.background = "black"');
}
}
}
function play() {
let num = document.querySelector('input').value;
if (num > 100) {
alert("Less than 100")
}
makeRow(num);
makeColumn(num);
}
function deleteContent() {
if (document.getElementById('container').textContent != " ") {
container.textContent = "";
}
}
// Previous functioned used to start game with a prompt
// function play() {
// let request = prompt("How squares per side should the board be?", "Choose from 10 to 100");
// if (request > 100) {
// let request = prompt("Sorry, it needs to be less than 101.", "What will it be?");
// }
// makeRow(request);
// makeColumn(request);
// }