-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.html
122 lines (113 loc) · 4.18 KB
/
calc.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
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/10.6.4/math.js"
integrity="sha512-BbVEDjbqdN3Eow8+empLMrJlxXRj5nEitiCAK5A1pUr66+jLVejo3PmjIaucRnjlB0P9R3rBUs3g5jXc8ti+fQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/10.6.4/math.min.js"
integrity="sha512-iphNRh6dPbeuPGIrQbCdbBF/qcqadKWLa35YPVfMZMHBSI6PLJh1om2xCTWhpVpmUyb4IvVS9iYnnYMkleVXLA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="fontawesome.js"></script>
<style>
* {
margin: 0;
padding: 0;
font-family: Inter;
box-sizing: border-box;
overflow: hidden;
transition: all 0.1s ease;
}
.headerpart button {
padding: 5px;
box-sizing: border-box;
}
button {
background: none;
border: none;
border-radius: 2.5px;
color: white;
transition: all 0.1s ease;
padding: 5px;
font-weight: bold;
}
button:hover {
background: #4d4d4d90;
border: none;
border-radius: 2.5px;
transition: all 0.1s ease;
}
button:active {
background: #4d4d4d;
border: none;
border-radius: 2.5px;
transition: all 0.1s ease;
}
input[type="button"] {
width: calc(25% - 4px);
font-size: 24px;
font-weight: bold;
border: none;
background: none;
border-radius: 5px;
height: 75.3px;
box-sizing: border-box;
height: calc(25% - 12px);
}
input[type="button"]:hover {
background: #eaeaea;
}
#result {
height: 39px;
width: 100%;
box-sizing: border-box;
font-size: 2em;
text-align: right;
font-weight: bold;
background: none;
border: none;
color: white;
}
</style>
<div style="padding: 5px; background: #1d1d1ddd; backdrop-filter: blur(10px); color: white; text-align: right;">
<input id="result">
</div>
<div style="width: 100%; background: lightgray;">
<tr>
<td><input type="button" value="1" onclick="dis('1')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="2" onclick="dis('2')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="3" onclick="dis('3')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="/" onclick="dis('/')" onkeydown="myFunction(event)"> </td>
</tr>
<tr>
<td><input type="button" value="4" onclick="dis('4')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="5" onclick="dis('5')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="6" onclick="dis('6')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="*" onclick="dis('*')" onkeydown="myFunction(event)"> </td>
</tr>
<tr>
<td><input type="button" value="7" onclick="dis('7')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="8" onclick="dis('8')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="9" onclick="dis('9')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="-" onclick="dis('-')" onkeydown="myFunction(event)"> </td>
</tr>
<tr>
<td><input type="button" value="0" onclick="dis('0')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="." onclick="dis('.')" onkeydown="myFunction(event)"> </td>
<td><input type="button" value="=" onclick="solve()"> </td>
<td><input type="button" value="+" onclick="dis('+')" onkeydown="myFunction(event)"> </td>
</tr>
</table>
</div>
<script>
function dis(val) {
document.getElementById("result").value += val
}
function solve() {
let x = document.getElementById("result").value
try {
let y = math.evaluate(x)
document.getElementById("result").value = y
} catch {
let y = 'Error'
document.getElementById("result").value = y
}
}
</script>