-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jomon joy
committed
Aug 10, 2024
0 parents
commit 8f1e482
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# calculator | ||
![Project image](https://github.com/Jomonh/calculator/blob/main/Preview.png) | ||
|
||
#### Live <a href="https://Jomonh.github.io/calculator/">here</a> | ||
## Getting started | ||
|
||
To clone this repository, run this in your command prompt/Terminal | ||
```bash | ||
git clone https://github.com/Jomonh/calculator.git | ||
``` | ||
and that's all you need to get started! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!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>Calculator App </title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<input type="text" class="display"> | ||
<div class="button"> | ||
<button class="operator opo" data-value="AC">AC</button> | ||
<button class="operator opo" data-value="DEL">DEL</button> | ||
<button class="operator opo" data-value="%">%</button> | ||
<button class="operator opo" data-value="/">/</button> | ||
<button data-value="7">7</button> | ||
<button data-value="8">8</button> | ||
<button data-value="9">9</button> | ||
<button class="operator opo" data-value="*">*</button> | ||
<button data-value="4">4</button> | ||
<button data-value="5">5</button> | ||
<button data-value="6">6</button> | ||
<button class="operator opo" data-value="-">-</button> | ||
<button data-value="1">1</button> | ||
<button data-value="2">2</button> | ||
<button data-value="3">3</button> | ||
<button class="operator opo" data-value="+">+</button> | ||
<button data-value="0">0</button> | ||
<button data-value="00">00</button> | ||
<button data-value=".">.</button> | ||
<button class="operator eq" data-value="=">=</button> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const display = document.querySelector(".display"); | ||
const buttons = document.querySelectorAll("button"); | ||
const specialChars = ["%", "*", "/", "-", "+", "="]; | ||
let output = ""; | ||
const calculate = (btnValue) => { | ||
display.focus(); | ||
if (btnValue === "=" && output !== "") { | ||
output = eval(output.replace("%", "/100")); | ||
} else if (btnValue === "AC") { | ||
output = ""; | ||
} else if (btnValue === "DEL") { | ||
output = output.toString().slice(0, -1); | ||
} else { | ||
if (output === "" && specialChars.includes(btnValue)) return; | ||
output += btnValue; | ||
} | ||
display.value = output; | ||
}; | ||
buttons.forEach((button) => { | ||
button.addEventListener("click", (e) => calculate(e.target.dataset.value)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400&display=swap'); | ||
|
||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: 'Poppins', sans-serif; | ||
} | ||
|
||
body{ | ||
height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background: #fff; | ||
} | ||
.container{ | ||
position: relative; | ||
max-width: 300px; | ||
width: 100%; | ||
border-radius: 20px; | ||
padding: 10px 20px 20px; | ||
background: #080707f2; | ||
box-shadow: 0 5px 10px rgba(0,0,0,0.05); | ||
outline: #333 10px solid; | ||
} | ||
.display{ | ||
height: 90px; | ||
width: 100%; | ||
outline: none; | ||
border: solid 0.3; | ||
text-align: right; | ||
margin: 50px 0; | ||
font-size: 40px; | ||
color: #000; | ||
pointer-events: none; | ||
} | ||
input{ | ||
background: #a19c9c70; | ||
border-radius: 12px; | ||
} | ||
.button{ | ||
display: grid; | ||
grid-gap: 12px; | ||
grid-template-columns: repeat(4, 1fr); | ||
} | ||
.button button{ | ||
padding: 10px; | ||
border-radius: 45px; | ||
border: none; | ||
font-size: 18px; | ||
font-weight: 600; | ||
cursor: pointer; | ||
background: linear-gradient(#272728 , #575658); | ||
} | ||
.button button:hover{ | ||
transition: .5s; | ||
background: linear-gradient(#575658 , #272728 ); | ||
} | ||
.button button:active{ | ||
transform: scale(0.99); | ||
} | ||
.operator{ | ||
color: #e1e1e1; | ||
} | ||
button.opo{ | ||
background: linear-gradient(rgb(36, 34, 34) ,rgb(56, 55, 55)); | ||
} | ||
button.opo:hover{ | ||
background: linear-gradient(rgb(56,55,55) ,rgb(36,34,34)) | ||
} | ||
button.eq{ | ||
background: linear-gradient(#b06803, #a35603); | ||
} | ||
button.eq:hover{ | ||
background:linear-gradient(#a35603, #b06803); | ||
} |