-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (38 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
45 lines (38 loc) · 1.2 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
let color = "black"
function populateBoard(size) {
let board = document.querySelector('.board')
let squares = board.querySelectorAll("div");
squares.forEach((div) => div.remove());
board.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
board.style.gridTemplateRows = `repeat(${size}, 1fr)`;
let amount = size * size
for(let i = 0; i<amount; i++) {
let square = document.createElement("div");
square.addEventListener('mouseover', colorSquare)
square.style.backgroundColor = "white"
board.insertAdjacentElement("beforeend", square)
}
}
populateBoard(16);
function changeSize(input) {
if(input >= 2 || input <= 100) {
populateBoard(input)
} else {
console.log("too many squares")
}
}
function colorSquare() {
if (color === "random") {
this.style.backgroundColor = `hsl(${Math.random() * 360}, 100%, 50%)`;
} else {
this.style.backgroundColor = color;
}
}
function changeColor(choice) {
color = choice;
}
function resetBoard() {
let board = document.querySelector('.board')
let squares = board.querySelectorAll("div");
squares.forEach((div) => div.style.backgroundColor = 'white');
}