Skip to content
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
Binary file added c10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions cal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
body{
background-image: url(c10.jpg);
background-repeat: no-repeat;
height: 100%;
width: 100%;
overflow: hidden;
background-position: center;
background-size: cover;
}
button{
width: 200px;
height: 50px;
margin: 2px 2px;
background-color: blue;
color: #fff4a7;
border-radius: 20px;
font-weight: bolder;
font-style: italic;
font-size: larger;
}
#outside{
color: white;
border-radius: 5px;
margin: auto;
margin-top: 100px;
width: 1000px;
height: 600px;
padding: 5px;
}
#heading{
margin: auto;
width: 412px;
font-size: xxx-large;
}
#btn{
margin: auto;
margin-top: 20px;
width: 815px;
}
.btn-inside{
width: 900px;
}
#val{
/* border: 2px solid red; */
height: 55px;
width: 783px;
margin-left: 100px;
color: white;
padding-left: 37px;
padding-top: 20px;
font-weight: bolder;
border:2px solid black;
}
#res{
/* border: 2px solid red; */
height: 50px;
width: 783px;
margin-left: 100px;
color: white;
padding-left: 37px;
padding-top: 25px;
font-weight: bolder;
font-size: x-large;
border:2px solid black;
}

58 changes: 58 additions & 0 deletions cal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!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="cal.css">
<title>Calculator</title>
</head>

<body>
<div id="outside">
<h1 id="heading">🖩CALCULATOR🖩</h1>
<div>
<div>
<h1 id="val"> </h1>
</div>
<div>
<p id="res"></p>
</div>
<div id="btn">
<div class="btn-inside">
<button onclick="adder('1')">1</button>
<button onclick="adder('2')">2</button>
<button onclick="adder('3')">3</button>
<button onclick="adder('*')">*</button>
</div>
<div class="btn-inside">
<button onclick="adder('4')">4</button>
<button onclick="adder('5')">5</button>
<button onclick="adder('6')">6</button>
<button onclick="adder('+')">+</button>
</div>
<div class="btn-inside">
<button onclick="adder('7')">7</button>
<button onclick="adder('8')">8</button>
<button onclick="adder('9')">9</button>
<button onclick="adder('-')">-</button>
</div>
<div class="btn-inside">
<button onclick="clearer()">C</button>
<button onclick="adder('0')">0</button>
<button onclick="compute(1)">=</button>
<button onclick="adder('/')">/</button>
</div>

<button onclick="adder('.')">.</button>

<button onclick="backspace()">x</button>

</div>
</div>
</div>
<script src="cal.js"></script>
</body>

</html>
52 changes: 52 additions & 0 deletions cal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
let valEl = document.getElementById("val")
let resEl = document.getElementById("res")

function backspace(){
let Res = resEl.innerText;
if(Res.trim().length === 0){
let value = valEl.innerText;
let slicedValue = value.slice(0,-1);
valEl.innerText = slicedValue;
}
}
function clearer() {
resEl.innerText = "";
valEl.innerText = "";
}

function adder(k){
valEl.innerText += k
if(k=='*' || k=='+' || k=='-' || k=='/'){
compute(0)
}
}
function compute(is){
let temp = valEl.innerText, i
let t = temp[temp.length-1];
for(i=0;i<temp.length-1;i++){
if((temp[i]=='*' || temp[i]=='+' || temp[i]=='-' || temp[i]=='/') && i!=0){
break;
}
}
if(i!=temp.length-1){
let part1 = parseFloat(temp.substring(0,i));
let part2 = parseFloat(temp.substring(i+1));
let k5 = temp[i];
if(k5=='+'){
resEl.innerText = (part1)+(part2);
}else if(k5=='-'){
resEl.innerText = (part1)-(part2);
}else if(k5=='*'){
resEl.innerText = (part1)*(part2);
}else{
resEl.innerText = (part1)/(part2);
}
resEl.innerText = '= ' + resEl.innerText
if(!is){
valEl.innerText = resEl.innerText + t
if(valEl.innerText[0] == '='){
valEl.innerText = valEl.innerText.substring(1)
}
}
}
}
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Create Simple Calculator using HTML, CSS and JavaScript

**Functionality**
1. Buttons to type number
2. Buttons to add, subtract, multiply and divide
3. Button to clear everything