HTML Code
<div class="cal-container">
<div class="result">
<div class="output"></div>
<input type="text" class="result">
</div>
<div class="first-row">
</div>
<div class="second-row">
<input type="button" name="" value="7" class="global number">
<input type="button" name="" value="8" class="global number">
<input type="button" name="" value="9" class="global number">
<input type="button" name="" value="%" class="global number">
</div>
<div class="third-row">
<input type="button" name="" value="4" class="global number">
<input type="button" name="" value="5" class="global number">
<input type="button" name="" value="6" class="global number">
<input type="button" name="" value="/" class="global number">
</div>
<div class="fourth-row">
<input type="button" name="" value="1" class="global number">
<input type="button" name="" value="2" class="global number">
<input type="button" name="" value="3" class="global number">
<input type="button" name="" value="*" class="global number">
</div>
<div class="conflict">
<div class="left">
<input type="button" name="" value="0" class="global grey number">
<input type="button" name="" value="." class="global number">
<input type="button" name="" value="-" class="global number">
<input type="button" name="" value="+" class="global grey number">
</div>
<input type="button" name="" value="Del" class=" red small white-text top-margin deleate">
<input type="button" name="" value="=" class=" green white-text big top-margin output_result">
</div>
Javascript Code
<script>
var user_value = document.querySelectorAll("input.number");
var screen_value = document.querySelector(".result input");
var my_calulate_value = undefined;
var result_out_put = document.querySelector(".result .output");
var result_btn = document.querySelector(".output_result")
var after_calcualtion = " ";
var deleate_btn = document.querySelector("input.deleate")
user_value.forEach(
function(x) {
x.addEventListener("click", function() {
var input_value = x.value;
screen_value.value += input_value;
after_calcualtion = (eval(screen_value.value));
//console.log(after_calcualtion)
})
})
result_btn.addEventListener("click",
function() {
result_out_put.innerText = after_calcualtion
})
deleate_btn.addEventListener("click",
function() {
screen_value.value = '';
result_out_put.innerText=' ';
})
</script>
Css Code
<style>
h1{
text-align: center;
margin-top: 0.67em;
margin-bottom: 0.67em;
}
*{
margin: 0;
padding: 0;
}
.cal-container{
margin: auto;
width: 25%;
padding: 10px;
border: 1px solid #f2f2f2;
-webkit-box-shadow: 1px 1px 4px 0px rgba(176,176,176,1);
-moz-box-shadow: 1px 1px 4px 0px rgba(176,176,176,1);
box-shadow: 1px 1px 4px 0px rgba(176,176,176,1);
background-color: #fff;
background-color: #F8F8F8;
}
.header{
background-color: #81C784;
padding: 10px;
color: #fff;
text-align: center;
}
.result{
font-size: 24px;
padding: 10px 5px;
font-weight: 700;
text-align: right;
width: 96%;
border: none;
background-color:#ffffff;
border:none;
}
.result:focus{
outline:none;
}
.first-row,
.second-row,
.third-row,
.fourth-row,
.conflict
{
display: inline-block;
width: 100%;
}
.global{
padding: 15px;
font-weight: bold;
font-size: 16px;
border: none;
border-radius: 3px;
background-color: #F2F2F2;
float: left;
width: 23.5%;
margin: 0 2px;
/*border: 1px solid #000;*/
}
.conflict .left,
.conflict .right{
float: left;
position: relative;
}
.left{
width: 100%;
}
.right{
width: 100%;
}
.big{
padding: 15px;
font-weight: bold;
font-size: 16px;
border: none;
border-radius: 3px;
background-color: #F2F2F2;
float: left;
width: 64.5%;
margin: 0 2px;
}
.small{
padding: 15px;
font-weight: bold;
font-size: 16px;
border: none;
border-radius: 3px;
background-color: #F2F2F2;
float: left;
width: 31.5%;
margin: 0 2px;
}
.plus{
height: 105px;
width: 100%;
}
.green{
background-color: #81C784;
}
.red{
background-color: #F50258
}
.grey{
background-color: #F2F2F2;
}
.white-text{
color: #fff;
}
.top-margin{
margin-top: 4px;
}
</style>
Live Privew