-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.HTML
More file actions
223 lines (194 loc) · 6.73 KB
/
index.HTML
File metadata and controls
223 lines (194 loc) · 6.73 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<style>
:root {
--bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--calc-bg: rgba(255, 255, 255, 0.95);
--btn-digit: #ffffff;
--btn-op: #f1f3f7;
--accent: #6c5ce7;
--text-main: #2d3436;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: var(--bg-gradient);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
width: 100%;
max-width: 400px; /* Tablet/Desktop limit */
background: var(--calc-bg);
padding: 25px;
border-radius: 30px;
box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}
/* Responsive adjustments for Phone */
@media (max-width: 400px) {
.container {
padding: 15px;
border-radius: 20px;
}
.button {
height: 55px !important;
font-size: 18px !important;
}
}
.display-area {
background: #f8f9fa;
padding: 20px;
border-radius: 20px;
margin-bottom: 25px;
text-align: right;
box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
}
#input {
width: 100%;
border: none;
outline: none;
font-size: 2rem;
background: transparent;
text-align: right;
color: var(--text-main);
font-weight: 600;
}
#para {
height: 25px;
color: #a0a0a0;
font-size: 1rem;
margin-bottom: 5px;
}
.button-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
.button {
height: 65px;
border: none;
border-radius: 18px;
font-size: 20px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
background: var(--btn-digit);
color: var(--text-main);
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.button:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0,0,0,0.1);
background: #fdfdfd;
}
.button:active {
transform: translateY(0);
}
/* Different Colors for Operators */
.mathButtons {
background: var(--btn-op);
color: var(--accent);
}
.action-btn {
color: #ff7675;
}
#sum {
background: var(--accent);
color: white;
grid-column: span 1;
}
#sum:hover {
background: #5b4bc4;
}
.zero {
grid-column: span 2;
}
</style>
</head>
<body>
<div class="container">
<div class="display-area">
<p id="para"></p>
<input type="text" id="input" placeholder="0" readonly>
</div>
<div class="button-grid">
<button class="button action-btn" onclick="cl()">AC</button>
<button class="button action-btn" onclick="del()">⌫</button>
<button class="button mathButtons" onclick="func('/')">÷</button>
<button class="button mathButtons" onclick="func('*')">×</button>
<button class="button" onclick="func('7')">7</button>
<button class="button" onclick="func('8')">8</button>
<button class="button" onclick="func('9')">9</button>
<button class="button mathButtons" onclick="func('-')">−</button>
<button class="button" onclick="func('4')">4</button>
<button class="button" onclick="func('5')">5</button>
<button class="button" onclick="func('6')">6</button>
<button class="button mathButtons" onclick="func('+')">+</button>
<button class="button" onclick="func('1')">1</button>
<button class="button" onclick="func('2')">2</button>
<button class="button" onclick="func('3')">3</button>
<button id="sum" class="button" onclick="ev()">=</button>
<button class="button zero" onclick="func('0')">0</button>
<button class="button" onclick="func('.')">.</button>
<button class="button mathButtons" onclick="func('%')">%</button>
</div>
</div>
<script>
const inpt = document.getElementById("input");
const para = document.getElementById("para");
function func(tag) {
const lastChar = inpt.value.slice(-1);
const operators = ['+', '-', '*', '/', '%'];
// Multiple operators bug fix
if (operators.includes(tag) && operators.includes(lastChar)) {
inpt.value = inpt.value.slice(0, -1) + tag;
}
else if (inpt.value === "" && operators.includes(tag) && tag !== '-') {
return;
}
else {
inpt.value += tag;
}
// Live Preview
try {
if(inpt.value.length > 0) {
para.innerHTML = eval(inpt.value.replace('×', '*').replace('÷', '/'));
}
} catch(e) { para.innerHTML = ""; }
}
function ev() {
try {
if (inpt.value !== "") {
// Replace icons with real math symbols for eval
let expression = inpt.value;
let result = eval(expression);
inpt.value = Number.isInteger(result) ? result : result.toFixed(2);
para.innerHTML = "";
}
} catch (e) {
inpt.value = "Error";
setTimeout(cl, 1500);
}
}
function cl() {
inpt.value = "";
para.innerHTML = "";
}
function del() {
inpt.value = inpt.value.slice(0, -1);
if(inpt.value === "") para.innerHTML = "";
}
</script>
</body>
</html>