-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculator.htm
146 lines (131 loc) · 4.82 KB
/
calculator.htm
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
144
145
146
<!DOCTYPE html>
<head>
<title>Calculator by David</title>
<meta charset="UTF-8">
<style type="text/css">
.add-button {
padding: 1.5px 1px;
background-color: white;
border: 5px solid red;
border-radius: 12px
display: incline-block;
font-size: 15px;
color: black;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
.add-button:hover {
padding: 2px 1px;
background-color: red;
border: 5px solid red;
border-radius: 12px
display: incline-block;
font-size: 15px;
color: white;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
.input-element{
font-size: 20px;
width: 100px;
position:absolute;
left:20px;
}
.calculator {
border:2px solid black;
background-color:grey;
height:200px;
width:130px;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
.operation-button {
width: 23px;
height:30px;
background-color: white;
color: black;
position:absolute;
border: 2px solid #4CAF50;
}
.operation-button:hover {
background-color: green;
color: white;
border: 2px solid #4CAF50;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
.text {
color:white;
position:absolute;
left:30px;
}
.super-button {
height: 24px;
width: 36.5px;
background-color: white;
border: 5px solid blue;
border-radius: 12px
display: incline-block;
font-size: 10px;
color: black;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
.super-button:hover {
height: 24px;
width: 36.5px;
background-color: blue;
border: 5px solid blue;
border-radius: 12px
display: incline-block;
font-size: 10px;
color: white;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19)
}
</style>
<head>
<body>
<article class="calculator">
<label for="fname" class="text">Calculator:</label><br>
<input type="text" id="input" class="input-element" value="0"><br>
<script >
function AC() {
document.getElementById("input").value = "0";
}
function addnumber(number) {
var value = document.getElementById("input").value
if (value == "0") {
document.getElementById("input").value = number;
}
else {
if (value.length < 10) {
document.getElementById("input").value += number;
}
}
}
function calc() {
function calculate(fn) {
return new Function('return ' + fn)();
}
var value = document.getElementById("input").value;
try {
document.getElementById("input").value = calculate(value);
} catch(err) {
alert("error!");
document.getElementById("input").value = "0";
}
}
</script>
<button style = "position:absolute;left: 92px;top:60px;"class = "add-button" id="clear-AC" onclick="AC()">AC</button>
<button style = "position:absolute;left: 92px;top:91px;"class = "super-button" id="add" onclick="addnumber('+')"> + </button>
<button style = "position:absolute;left: 92px;top:116px;"class = "super-button" id="minus" onclick="addnumber('-')"> - </button>
<button style = "position:absolute;left: 92px;top:141px;"class = "super-button" id="multiply" onclick="addnumber('*')"> x </button>
<button style = "position:absolute;left: 92px;top:163px;"class = "super-button" id="divide" onclick="addnumber('/')"> ÷ </button>
<button style = "position:absolute;left: 45px;top:155px;width:40.5px;"class = "add-button" id="calculate" onclick="calc()"> = </button>
<button style = "position:absolute;left: 19.5px;top: 60px;"class="operation-button" id="add-number" onclick="addnumber(1)">1</button>
<button style = "position:absolute;left: 43.5px;top: 60px;"class="operation-button" id="add-number" onclick="addnumber(2)">2</button>
<button style = "position:absolute;left: 67.5px;top: 60px;"class="operation-button" id="add-number" onclick="addnumber(3)">3</button>
<button style = "position:absolute;left: 19.5px;top: 92px;"class="operation-button" id="add-number" onclick="addnumber(4)">4</button>
<button style = "position:absolute;left: 43.5px;top: 92px;"class="operation-button" id="add-number" onclick="addnumber(5)">5</button>
<button style = "position:absolute;left: 67.5px;top: 92px;"class="operation-button" id="add-number" onclick="addnumber(6)">6</button>
<button style = "position:absolute;left: 19.5px;top: 124px;"class="operation-button" id="add-number" onclick="addnumber(7)">7</button>
<button style = "position:absolute;left: 43.5px;top: 124px;"class="operation-button" id="add-number" onclick="addnumber(8)">8</button>
<button style = "position:absolute;left: 67.5px;top: 124px;"class="operation-button" id="add-number" onclick="addnumber(9)">9</button>
<button style = "position:absolute;left: 19.5px;top: 156px;box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);"class="operation-button" id="add-number" onclick="addnumber(0)">0</button>
</article>
</body>