-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (40 loc) · 1.01 KB
/
app.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
53
54
55
56
57
// set initial count
let count = 0;
// select value
const value = document.querySelector("#value")
// console.log(value);
// select all buttons
const buttonsAll = document.querySelectorAll(".btn")
// console.log(buttonsAll);
buttonsAll.forEach(function(button){
// console.log(button);
button.addEventListener("click", function(e){
// * save in a variable
const classList = e.currentTarget.classList;
console.log(classList);
// console.log(e.currentTarget.classList);
if(classList.contains("decrease")){
count--;
}
else if(classList.contains("increase")){
count++;
}
// else{
// count = 0;
// }
else if(classList.contains("reset")){
count = 0
}
// choose color
if(count<0){
value.style.color = "red"
}
if(count>0){
value.style.color ="green"
}
if(count===0){
value.style.color = "#222"
}
value.textContent = count
})
})