-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (43 loc) · 1.36 KB
/
main.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
// counter
const blackCounterLable = document.querySelector('#blackC p');
const whiteCounterLable = document.querySelector('#whiteC p');
let blackCounter = 2;
let whiteCounter = 2;
function counterUpdater() {
blackCounterLable.innerHTML = blackCounter;
whiteCounterLable.innerHTML = whiteCounter;
}
counterUpdater();
const container = document.querySelector('#container');
const blocks = document.querySelectorAll('.block');
const nobat = document.querySelector('#nobat');
let turnblack = false;
blocks.forEach(e => {
e.addEventListener('click', () => {
if (e.classList.length === 1) {
if (turnblack === true) {
e.classList.add("black");
blackCounter++;
turnblack = false;
} else {
e.classList.add("white");
whiteCounter++;
turnblack = true;
}
nobat.classList.toggle("black");
} else {
if (e.classList.contains("black")) {
e.classList.remove("black");
blackCounter--;
e.classList.add("white");
whiteCounter++;
} else {
e.classList.remove("white");
whiteCounter--;
e.classList.add("black");
blackCounter++;
}
}
counterUpdater();
})
});