-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_counter.html
96 lines (87 loc) · 2.59 KB
/
07_counter.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counter Project</title>
<style>
main {
display: flex;
flex-direction: column;
font-family: Arial, Helvetica, sans-serif;
}
.counter-cont {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 100px;
}
.counter-cont p {
font-size: 3em;
margin-bottom: 4px;
text-transform: uppercase;
}
.buttons-cont {
display: flex;
flex-direction: column;
}
.buttons-cont button {
background-color: blue;
color: white;
width: 150px;
padding: 10px;
margin: 6px 0;
text-transform: uppercase;
border: 1px solid green;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
#counter {
font-size: 10em;
text-align: center;
}
</style>
</head>
<body>
<main>
<section class="counter-cont">
<p>Counter</p>
<div id="counter">0</div>
<div class="buttons-cont">
<button type="button" id="lowerCountBtn">Lower Count</button>
<button type="button" id="addCountBtn">Add Count</button>
</div>
</section>
</main>
<script>
const COUNTER_AREA = document.querySelector('#counter');
const LOWER_COUNT_BTN = document.querySelector('#lowerCountBtn');
const ADD_COUNT_BTN = document.querySelector('#addCountBtn');
let count = 0;
COUNTER_AREA.innerHTML = count;
LOWER_COUNT_BTN.addEventListener('click', lowerCount)
ADD_COUNT_BTN.addEventListener('click', addCount);
function lowerCount() {
count--;
switchColor(count);
COUNTER_AREA.innerHTML = count;
}
function addCount() {
count++;
switchColor(count);
COUNTER_AREA.innerHTML = count;
}
function switchColor(val) {
if (count > 0) {
COUNTER_AREA.style.color = "green";
} else if (count < 0) {
COUNTER_AREA.style.color = "red";
} else {
COUNTER_AREA.style.color = "black";
}
}
</script>
</body>
</html>