-
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
1 parent
4c945d4
commit 70db05d
Showing
3 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Calculator</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="main-container"> | ||
<div id="heading-div"> | ||
<h1 id="heading">CALCULATOR</h1> | ||
</div> | ||
<div id="display"></div> | ||
<div id="function-div"> | ||
<div id="ac" class="button">AC</div> | ||
<div id="pluse_minus" class="button">+/-</div> | ||
<div id="percentage" class="button">%</div> | ||
<div class="button operation">/</div> | ||
<div class="button no">7</div> | ||
<div class="button no">8</div> | ||
<div class="button no">9</div> | ||
<div class="button operation">*</div> | ||
<div class="button no">4</div> | ||
<div class="button no">5</div> | ||
<div class="button no">6</div> | ||
<div class="button operation">-</div> | ||
<div class="button no">1</div> | ||
<div class="button no">2</div> | ||
<div class="button no">3</div> | ||
<div class="button operation">+</div> | ||
<div class="button no zero">0</div> | ||
<div class="button no">.</div> | ||
<div id="equal" class="button">=</div> | ||
</div> | ||
</div> | ||
|
||
<script src="index.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,58 @@ | ||
const num = document.querySelectorAll('.no'); | ||
const operation = document.querySelectorAll('.operation'); | ||
|
||
const percent = document.getElementById('percentage'); | ||
const pluse_minus = document.getElementById('pluse_minus'); | ||
const ac = document.getElementById('ac'); | ||
const equal = document.getElementById('equal'); | ||
const display = document.getElementById('display'); | ||
|
||
let ans = 0; | ||
let operand = ''; | ||
|
||
num.forEach((ele)=> { | ||
ele.addEventListener('click', ()=>{ | ||
if (display.innerText == '') { | ||
display.innerText = ele.innerText; | ||
} else { | ||
if (display.innerText.includes('.') && ele.innerText == '.') { | ||
return; | ||
} | ||
display.innerText = display.innerText + ele.innerText; | ||
} | ||
}) | ||
}) | ||
operation.forEach((ele) =>{ | ||
ele.addEventListener('click', ()=>{ | ||
if (display.innerText != '') { | ||
if (operand != '') { | ||
ans = eval(ans + " " + operand + " " +display.innerText); | ||
} else{ | ||
ans = display.innerText; | ||
} | ||
display.innerText = ''; | ||
} | ||
operand = ele.innerText; | ||
}) | ||
}) | ||
percent.addEventListener('click', ()=>{ | ||
if(display.innerText != ''){ | ||
display.innerText = (parseFloat(display.innerText/100)); | ||
ans = display.innerText; | ||
} | ||
}) | ||
pluse_minus.addEventListener('click', ()=>{ | ||
display.innerText = display.innerText*(-1); | ||
}) | ||
equal.addEventListener('click', ()=>{ | ||
if (operand != '') { | ||
ans = eval(ans + " " + operand + " " +display.innerText); | ||
} | ||
operand = ''; | ||
display.innerText = ans; | ||
}) | ||
ac.addEventListener('click', ()=> { | ||
display.innerText = ''; | ||
ans = 0; | ||
operand = ''; | ||
}) |
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,75 @@ | ||
body { | ||
margin: 0; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
} | ||
#main-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 500px; | ||
width: 400px; | ||
padding: 5px; | ||
margin-top: 40px; | ||
background-color: lightgray; | ||
} | ||
#heading { | ||
height: 40px; | ||
width: 340px; | ||
padding: 10px 0; | ||
margin: 10px 5px; | ||
text-align: center; | ||
color: white; | ||
background-color: black; | ||
} | ||
#display{ | ||
height: 60px; | ||
width: 320px; | ||
padding: 14px 10px 6px; | ||
text-align: end; | ||
font-size: 40px; | ||
color: rgb(0, 68, 255); | ||
background-color: rgb(255, 255, 255); | ||
border-radius: 10px; | ||
box-shadow: inset 0px 0px 8px gray; | ||
margin: 10px 5px 5px; | ||
} | ||
|
||
#function-div { | ||
display: flex; | ||
flex-wrap: wrap; | ||
/* flex-direction: ; */ | ||
margin: 5px; | ||
} | ||
.button { | ||
height: 38px; | ||
width: 83px; | ||
padding: 8px 0 0 0; | ||
margin: 4px; | ||
font-size: 24px; | ||
font-weight: 550; | ||
text-align: center; | ||
background-color: white; | ||
box-shadow: 0px 2.2px 0px gray; | ||
border: 1px solid rgb(120, 120, 120); | ||
} | ||
.button:hover { | ||
color: white; | ||
border: 1px solid rgb(200, 100, 0); | ||
box-shadow: 0px 2.2px 0px rgb(255, 50, 0); | ||
background-color: orangered; | ||
} | ||
#ac, #pluse_minus, #percentage { | ||
color: white; | ||
background-color: darkgray; | ||
} | ||
.zero { | ||
width: 176px; | ||
} | ||
.operation, #equal { | ||
color: lightgray; | ||
background-color: brown; | ||
} |