Skip to content

Commit f6168c2

Browse files
committed
added counter
1 parent 557225a commit f6168c2

File tree

8 files changed

+184
-1
lines changed

8 files changed

+184
-1
lines changed

blocks/counter.css

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/counter.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/counter.scss

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
main {
2+
height: 100vh;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
}
7+
8+
.main {
9+
&__inner {
10+
}
11+
12+
&__title {
13+
text-align: center;
14+
font-family: 'Roboto Mono', monospace;
15+
}
16+
17+
&__counter {
18+
margin-top: 20px;
19+
}
20+
}
21+
22+
.counter {
23+
background-color: white;
24+
border-radius: 30px;
25+
padding: 30px;
26+
&__output {
27+
text-align: center;
28+
font-size: 72px;
29+
}
30+
31+
&__buttons {
32+
margin-top: 15px;
33+
display: flex;
34+
flex-wrap: wrap;
35+
gap: 15px;
36+
}
37+
38+
&__btn {
39+
color: inherit;
40+
font-size: inherit;
41+
background-color: transparent;
42+
border: 1px solid black;
43+
border-radius: 30px;
44+
padding: 8px 16px;
45+
46+
transition: .3s ease;
47+
&:hover {
48+
color: white;
49+
background-color: black;
50+
}
51+
}
52+
}

blocks/index.css

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/index.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/main-page/01.png

7.63 KB
Loading

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ <h1 class="main__title">Small JavaScript Projects</h1>
2020
<img src="images/main-page/01.png" alt="Counter">
2121
</a>
2222
<a href="pages/counter.html" class="cards-block__title">Counter</a>
23-
<p class="cards-block__subtitle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci magnam minima neque quae tenetur! Eius fugiat itaque non praesentium voluptatem?</p>
23+
<p class="cards-block__subtitle">Simple counter.
24+
User can decrement, reset and increment counter.</p>
2425
</div>
2526

2627
</div>

scripts/counter.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
let counter = 0
2+
3+
const value = document.querySelector('.counter__output')
4+
const buttons = document.querySelector('.counter__buttons')
5+
6+
buttons.addEventListener("click", valueHandler)
7+
8+
function valueHandler(e) {
9+
if (e.target.innerText === 'Decrement') {
10+
counter--
11+
} else if (e.target.innerText === 'Reset') {
12+
counter = 0
13+
} else {
14+
counter++
15+
}
16+
value.innerHTML = counter
17+
18+
if (counter < 0) {
19+
value.style.color = "red";
20+
} else if (counter !== 0) {
21+
value.style.color = "green";
22+
} else {
23+
value.style.color = "black";
24+
}
25+
}

0 commit comments

Comments
 (0)