Skip to content

Commit

Permalink
Add counter project
Browse files Browse the repository at this point in the history
  • Loading branch information
ttt30ga committed Apr 13, 2022
1 parent ed04b47 commit 5420d07
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 7 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Mini projects built with HTML, CSS and JavaScript
| # | Project |
| -- | ------- |
| 01 | [Clock](./clock/) |
| 02 | [Color Flip](./color-flip/) |
| 03 | [Dice Game](./dice-game/) |
| 04 | [BMI Calculator](./bmi-calculator/) |
| 05 | [Drum Kit](./drum-kit/) |
| 06 | [Simon Game](./simon-game/) |
| 07 | [Calculator](./calculator/) |
| 08 | [Form Validator](./form-validator/) |
| 02 | [Counter](./counter/) |
| 03 | [Color Flip](./color-flip/) |
| 04 | [Dice Game](./dice-game/) |
| 05 | [BMI Calculator](./bmi-calculator/) |
| 06 | [Drum Kit](./drum-kit/) |
| 07 | [Simon Game](./simon-game/) |
| 08 | [Calculator](./calculator/) |
| 09 | [Form Validator](./form-validator/) |
4 changes: 4 additions & 0 deletions counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Counter
Counter made in HTML, CSS, JS

![counter](./images/counter.gif)
Binary file added counter/images/counter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions counter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!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">
<link rel="stylesheet" href="style.css">
<title>Counter</title>
</head>
<body>
<h1>Counter</h1>
<div class="container">
<div class="counter" id="counter">0</div>
<div class="buttons">
<button class="btn btn-primary" id="increase">increase</button>
<button class="btn btn-primary" id="decrease">decrease</button>
<button class="btn btn-primary" id="reset">reset</button>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions counter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const txtCounter = document.querySelector('#counter')
const btnIncrease = document.querySelector('#increase')
const btnDecrease = document.querySelector('#decrease')
const btnReset = document.querySelector('#reset')

let counter = 0

function count() {
btnIncrease.addEventListener('click', () => {
counter++
txtCounter.textContent = counter
addClass()
})

btnDecrease.addEventListener('click', () => {
counter--
txtCounter.textContent = counter
addClass()
})

btnReset.addEventListener('click', () => {
counter = 0
txtCounter.textContent = counter
addClass()
})

console.log(counter);
}

function addClass() {
if (counter < 0) {
txtCounter.classList.add('red')
txtCounter.classList.remove('green')
} else if (counter > 0) {
txtCounter.classList.add('green')
txtCounter.classList.remove('red')
} else {
txtCounter.classList.remove('green')
txtCounter.classList.remove('red')
}
}

count()
85 changes: 85 additions & 0 deletions counter/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@import url('https://fonts.googleapis.com/css2?family=Secular+One&display=swap');

:root {
--col-bg-1: #d0e4c9;
--col-bg-2: #82c3c6;
--col-bg-3: #5776a2;
--col-light: #f5fff5;
--col-btn: #ffab51;
--col-btn-hover: #fd9b32;
--col-btn-active: #ff8e15;
--col-red: #ff3752;
--col-green: #00c55c;
--ff: 'Secular One', sans-serif;
}

* {
margin: 0;
padding: 0;
font-family: var(--ff)
}

body {
display: flex;
min-height: 100vh;
flex-direction: column;
background-image: linear-gradient(var(--col-bg-1), var(--col-bg-2), var(--col-bg-3));
color: var(--col-light);
}

h1 {
font-size: 3rem;
font-weight: 700;
text-align: center;
color: var(--col-bg-3);
margin: 2rem;
}

.container {
display: flex;
flex-direction: column;
align-items: center;
}

.buttons {
display: flex;
flex-direction: row;
margin-top: 2rem;
}

.counter {
color: var(--col-light);
font-size: 12rem;
font-weight: 300;
}

.btn {
font-size: 2rem;
border-radius: 1.4rem;
border: none;
padding: 0.4rem 1.6rem;
cursor: pointer;
}

.btn-primary {
margin: 0.4rem;
background-color: var(--col-btn);
color: var(--col-light);
}

.btn-primary:hover {
background-color: var(--col-btn-hover);
}

.btn-primary:active {
background-color: var(--col-btn-active);
color: var(--col-dark);
}

.red {
color: var(--col-red);
}

.green {
color: var(--col-green);
}

0 comments on commit 5420d07

Please sign in to comment.