Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a calculator web app in HTML,Css and Js #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Js- Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!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">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="heading">
<h1>Calculator</h1>
</div>
<div id="calculator">
<!-- <div id="screen"></div> -->
<input type="text" id="screen">
<div class="controls">
<button class="btn" id="btn-1">(</button>
<button class="btn" id="btn-2">)</button>
<button class="btn" id="btn-3">C</button>
<button class="btn" id="btn-4">B</button>
<button class="btn" id="btn-5">7</button>
<button class="btn" id="btn-6">8</button>
<button class="btn" id="btn-7">9</button>
<button class="btn" id="btn-8">X</button>
<button class="btn" id="btn-9">4</button>
<button class="btn" id="btn-10">5</button>
<button class="btn" id="btn-11">6</button>
<button class="btn" id="btn-12">-</button>
<button class="btn" id="btn-13">1</button>
<button class="btn" id="btn-14">2</button>
<button class="btn" id="btn-15">3</button>
<button class="btn" id="btn-16">+</button>
<button class="btn" id="btn-17">0</button>
<button class="btn" id="btn-18">.</button>
<button class="btn" id="btn-19">/</button>
<button class="btn" id="btn-20">=</button>
</div>
</div>
</div>
</body>
<script src="index.js"></script>
</html>
29 changes: 29 additions & 0 deletions Js- Calculator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let screen= document.getElementById('screen');
buttons= document.querySelectorAll('button');
let screenValue='';
for (item of buttons) {
item.addEventListener('click',(e)=>{
buttonText= e.target.innerText;
console.log(buttonText);
if(buttonText=='X'){
buttonText='*';
screenValue+=buttonText;
screen.value=screenValue;
}
else if(buttonText=='C'){
screenValue= "";
screen.value=screenValue;
}
else if(buttonText=='B')
{
screen.value = screen.value.substring(0, screen.value.length - 1);
}
else if(buttonText=='='){
screen.value=eval(screenValue);
}
else{
screenValue+=buttonText;
screen.value=screenValue;
}
})
}
47 changes: 47 additions & 0 deletions Js- Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
*{
padding: 0;
margin: 0;
}
.container{
padding: 20px;
}
.heading{
text-align: center;
}
#calculator{
border: 4px solid black;
border-radius: 20px;
margin-right: 550px;
margin-left: 550px;
margin-top: 50px ;
margin-bottom: 80px ;
height: 500px;
padding: 15px;
padding-bottom: 0px;
background-color: #8584a2;
}
#screen{
border: 2px solid black;
box-sizing: border-box;
padding: 10px;
width: 339px;
font-size: 30px;
border-radius: 20px;
height: 70px;
margin-bottom: 10px;
background-color: rgb(245, 245, 204);
}
.controls{
box-sizing: border-box;
/* border: 4px solid black; */
height: 400px;
display: grid;
grid-template-columns: auto auto auto auto;
padding: 5px ;
}
.btn{
margin: 5px;
font-size: 20px;
border-radius: 16px;
padding: 4px;
}