-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (34 loc) · 987 Bytes
/
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
const main = document.querySelector("main");
const reset = document.querySelector("button");
const counter = document.querySelector(".counter");
const leftBlock = document.querySelector(".left-block");
const rightBlock = document.querySelector(".right-block");
let blockA = 0;
let blockB = 100;
let percentColor = 0;
main.addEventListener("click", addCount);
reset.addEventListener("click", resetCount);
document.addEventListener("keypress", function (whichKey) {
if (whichKey.key === " " || whichKey.key === "Enter") {
addCount();
}
});
function addCount() {
percentColor++;
blockA++;
blockB--;
counter.innerText = percentColor;
leftBlock.style.width = `${blockA}%`;
rightBlock.style.width = `${blockB}%`;
if (percentColor === 101) {
return resetCount();
}
}
function resetCount() {
percentColor = 0;
blockA = 0;
blockB = 100;
counter.innerText = percentColor;
leftBlock.style.blockA = `${blockA}%`;
rightBlock.style.blockB = `${blockB}%`;
}