Skip to content

Commit 359c443

Browse files
committed
counter app
1 parent f2873eb commit 359c443

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎2-counter/setup/app.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const counterSpan = document.querySelector('#value')
2+
const buttonContainer = document.querySelector('.button-container')
3+
const decreaseButton = document.querySelector('.decrease')
4+
const resetButton = document.querySelector('.reset')
5+
const increaseButton = document.querySelector('.increase')
6+
7+
let counterValue = 0
8+
9+
const allButtons = document.querySelectorAll('.btn')
10+
11+
decreaseButton.addEventListener('click', function (e) {
12+
counterValue -= 1
13+
counterSpan.textContent = counterValue
14+
if (counterValue < 0) counterSpan.style.color = 'red'
15+
if (counterValue === 0) counterSpan.style.color = '#222'
16+
})
17+
resetButton.addEventListener('click', function (e) {
18+
counterValue = 0
19+
counterSpan.textContent = counterValue
20+
if (counterValue === 0) counterSpan.style.color = '#222'
21+
})
22+
23+
increaseButton.addEventListener('click', function (e) {
24+
counterValue += 1
25+
counterSpan.textContent = counterValue
26+
if (counterValue > 0) counterSpan.style.color = 'green'
27+
if (counterValue === 0) counterSpan.style.color = '#222'
28+
})

‎2-counter/setup/index.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
<link rel="stylesheet" href="styles.css" />
1010
</head>
1111
<body>
12-
<h1>your code goes here</h1>
12+
<main>
13+
<h1>Counter</h1>
14+
<span id="value">0</span>
15+
<div class="button-container">
16+
<button class="btn decrease">Decrease</button>
17+
<button class="btn reset">Reset</button>
18+
<button class="btn increase">Increase</button>
19+
</div>
20+
</main>
1321
<!-- javascript -->
1422
<script src="app.js"></script>
1523
</body>

0 commit comments

Comments
 (0)