-
Notifications
You must be signed in to change notification settings - Fork 382
/
JScalculator.html
146 lines (129 loc) · 3.14 KB
/
JScalculator.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
<!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>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap');
*{
margin:0;
padding:0;
box-sizing: border-box;
font-family:'Poppins', sans-serif;
}
body{
padding-top: 200px;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background:rgb(2, 2, 2);
}
.Calculator{
border:1px solid rgb(96, 93, 93);
padding: 10px;
border-radius: 20px;
background: transparent;
box-shadow: 0px 3px 15px, rgba(113, 110, 110,0.7);
}
input{
width:320px;
border:none;
padding:20px;
margin:10px;
background: transparent;
box-shadow:0px 3px 15px rgbs;
font-size: 40px;
text-align: right;
cursor:pointer;
color:white;
}
input::placeholder{
color: white;
}
button{
border:none;
width:60px;
cursor:pointer;
margin:10px;
height:60px;
text-align: center;
border-radius: 50%;
color:white;
background:transparent;
box-shadow: -8px -8px 15px rgba(255,255,255,0.2);
font-size:20px;
}
.equal{
background-color: coral;
}
.operator{
background-color: rgb(103, 184, 184);
}
</style>
</head>
<body>
<div class="Calculator">
<input type="text" placeholder="0" id="inputBox">
<div>
<button class="operator">AC</button>
<button class="operator">DEL</button>
<button class="operator">%</button>
<button class="operator">/</button>
</div>
<div>
<button>7</button>
<button>8</button>
<button>9</button>
<button class="operator">*</button>
</div>
<div>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="operator">-</button>
</div>
<div>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="operator">+</button>
</div>
<div>
<button>00</button>
<button>0</button>
<button>.</button>
<button class="equal">=</button>
</div>
</div>
<script>
let input = document.getElementById('inputBox');
let buttons = document.querySelectorAll('button');
let string = "";
let arr = Array.from(buttons);
arr.forEach(button => {
button.addEventListener('click', (e) =>{
if(e.target.innerHTML == '='){
string = eval(string);
input.value = string;
}
else if(e.target.innerHTML == 'AC'){
string = "";
input.value = string;
}
else if(e.target.innerHTML == 'DEL'){
string = string.substring(0, string.length-1);
input.value = string;
}
else{
string += e.target.innerHTML;
input.value = string;
}
})
})
</script>
</body>
</html>