-
Notifications
You must be signed in to change notification settings - Fork 32
/
Standard_Calculator.html
143 lines (117 loc) · 4.59 KB
/
Standard_Calculator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!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>CALCULATOR</title>
<!-- css code -->
<style>
body {
font-family: 'Times New Roman', Times, serif;
}
#display_id {
height: 48px;
width: 269px;
border-radius: 63px;
margin-bottom: 8px;
border-color: saddlebrown;
background-color: rgba(13, 90, 90, 0.719);
text-align: right;
color: cornsilk;
font-size: larger;
box-shadow: rgb(0, 0, 0);
font-weight: bolder;
}
form {
margin-top: auto;
margin: auto;
border: 1px black groove;
height: auto;
height: auto;
width: 301px;
padding-top: 18px;
padding-bottom: 15px;
box-shadow: 5px 5px 29px rgb(0, 0, 0);
background-color: rgba(170, 167, 163, 0.637);
border-radius: 33px;
margin-top: 58px;
}
#btn {
width: 56px;
height: 51px;
margin: 2px;
padding: 2px;
padding-bottom: 27px;
padding-top: 17px;
border-radius: 32px;
text-align: center;
font-size: larger;
font-weight: bold;
box-shadow: 2px 2px 3px rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.548);
color: white;
}
#btn:hover {
background-color: rgba(0, 0, 0, 0.548);
background-color: aliceblue;
color: rgb(0, 0, 0);
cursor:pointer;
}
</style>
<!-- JAVASCRIPT code -->
<script>
function fun(given) {
var operand = document.getElementById('display_id').value;
document.getElementById('display_id').value = operand + given;
}
function calculation() {
oper = document.getElementById("display_id").value;
var len = oper.length;
if (len == 0) {
var temp = prompt("SORRY please enter expression to solve : ")
res1 = eval(temp);
document.getElementById("display_id").value = res1;
}
else {
res = eval(oper);
document.getElementById("display_id").value = res;
}
}
function del() {
var res = document.getElementById("display_id").value;
var val = res.length - 1;
var pr = res.slice(0, val);//this function takes start and end value for slicing particular string
document.getElementById("display_id").value = pr;
}
function clr() {
document.getElementById("display_id").value = " ";
}
</script>
</head>
<body>
<form align=center>
<input name="display" id='display_id' /><br>
<input type=button value=DEL id=btn style="background-color: rgb(223, 121, 84);" onclick="del()">
<input type=button value=C id=btn style="color: black;" onclick="clr()" />
<input type=button value=. id=btn style="color: black;" onclick="fun('.')" />
<input type=button value=+ id=btn style="color: black;" onclick="fun('+')" /></br>
<input type=button value=7 id=btn onclick="fun('7')" />
<input type=button value=8 id=btn onclick="fun('8')" />
<input type=button value=9 id=btn onclick="fun('9')" />
<input type=button value=* id=btn style="color:black;" onclick="fun('*')" /></br>
<input type=button value=4 id=btn onclick="fun('4')" />
<input type=button value=5 id=btn onclick="fun('5')" />
<input type=button value=6 id=btn onclick="fun('6')" />
<input type=button value=/ id=btn style="color: black;" onclick="fun('/')" /><br />
<input type=button value=1 id=btn onclick="fun('1')" />
<input type=button value=2 id=btn onclick="fun('2')" />
<input type=button value=3 id=btn onclick="fun('3')" />
<input type=button value=- id=btn style="color: black;" onclick="fun('-')" /><br>
<input type=button value=0 id=btn onclick="fun('0')" />
<input type=button value=00 id=btn onclick="fun('00')" />
<input type=button value=% id=btn style="color: black;" onclick="fun('%')" />
<input type=button value="=" style="background-color: rgb(223, 121, 84);" id=btn onclick="calculation()"></br>
</form>
</body>
</html>