-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
165 lines (157 loc) · 4.66 KB
/
index.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script>
<style>
button{
height: 70px;
width: 70px;
font-size: 30px;
background-color: #0000;
border-color: #00c3ff;
font-weight: 800;;
font-family: NSimSun;
}
#output{
border-radius:5px;
background-color:black;
color:white;
border:solid 1px black;
align: center;
width:300px;
height:50px;
font-size: 32px;
font-weight:400;
}
.equal-button{
height:150px;
}
table{
display:flex;
flex-wrap:wrap;
justify-content:center;
width:100%;
}
body{
background: linear-gradient(to right,white, #03d3fc, white);
height:100;
font-family: NSimSun;
}
</style>
</head>
<body>
<center>
<form name="form">
<input name="output" id="output" >
</form>
</center>
<div class="calc">
<table>
<tr>
<td><button onclick="clean()">C</button></td>
<td><button onclick="backspace()">CE</button></td>
<td><button onclick="add('/')">/</button></td>
<td><button onclick="add('*')">*</button></td>
</tr>
<tr>
<td><button onclick="add(7)">7</button></td>
<td><button onclick="add(8)">8</button></td>
<td><button onclick="add(9)">9</button></td>
<td><button onclick="add('-')">-</button></td>
</tr>
<tr>
<td><button onclick="add(4)">4</button></td>
<td><button onclick="add(5)">5</button></td>
<td><button onclick="add(6)">6</button></td>
<td><button onclick="add('+')">+</button></td>
</tr>
<tr>
<td><button onclick="add(1)">1</button></td>
<td><button onclick="add(2)">2</button></td>
<td><button onclick="add(3)">3</button></td>
<td rowspan=5 ><button class="equal-button" id="equal" onclick="equal()">=</button></td>
</tr>
<tr>
<td colspan=2 onclick="add(0)"><button style="width:150px">0</button></td>
<td><button onclick="add('.')">.</button></td>
</tr>
</table>
</div>
<script>
function add(num){
document.form.output.value+=num;
}
function clean(){
document.form.output.value="";
}
function equal(){
var exp= document.form.output.value;
if(exp){
document.form.output.value= eval(document.form.output.value);
}
}
function backspace(){
var exp= document.form.output.value;
document.form.output.value=exp.substring(0,exp.length-1);
}
// adding the working with keyboard feature
var body=document.querySelector("body");
body.addEventListener('keydown', function(event) {
const key = event.key;
if (key === "Backspace" || key === "Delete") {
backspace();
}
if (key === "Enter") {
equal();
}
if (key === '1') {
add(1);
}
if (key === '2') {
add(2);
}
if (key === '3') {
add(3);
}
if (key === '4') {
add(4);
}
if (key === '5') {
add(5);
}
if (key === '6') {
add(6);
}
if (key === '7') {
add(7);
}
if (key === '8') {
add(8);
}
if (key === '9') {
add(9);
}
if (key === '0') {
add(0);
}
if (key === '+') {
add('+');
}
if (key === '-') {
add('-');
}
if (key === '*') {
add('*');
}
if (key === '/') {
add('/');
}
if (key === '.') {
add('.');
}
});
</script>
</body>
</html>