Skip to content

Commit cfb2c5c

Browse files
authored
Update index.html
1 parent f81b52a commit cfb2c5c

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

index.html

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,20 @@
116116
</div>
117117
</div>
118118

119+
<!DOCTYPE html>
120+
<html lang="en">
121+
<head>
122+
<!-- ... (keep head section the same) ... -->
123+
</head>
124+
<body>
125+
<!-- ... (keep calculator HTML structure the same) ... -->
126+
119127
<script>
128+
/*
129+
// Original script (commented out)
120130
const display = document.getElementById('display');
121131
let lastOperator = null;
122132
123-
// Load last saved value
124133
document.addEventListener("DOMContentLoaded", () => {
125134
display.value = localStorage.getItem('calcDisplay') || '0';
126135
});
@@ -169,7 +178,6 @@
169178
localStorage.setItem('calcDisplay', display.value);
170179
}
171180

172-
// Keyboard support
173181
document.addEventListener('keydown', (e) => {
174182
if (e.key >= '0' && e.key <= '9') appendNumber(e.key);
175183
if (e.key === '.' && !display.value.split(/[\+\-\*/]/).pop().includes('.')) appendNumber('.');
@@ -179,6 +187,49 @@
179187
if (e.key === 'Escape') clearDisplay();
180188
if (e.key === '%') appendOperator('%');
181189
});
190+
*/
191+
</script>
192+
193+
<script>
194+
// New simplified script that shows HAPPY BIRTHDAY on =
195+
const display = document.getElementById('display');
196+
197+
// Initialize display
198+
display.value = '0';
199+
200+
function appendNumber(num) {
201+
if (display.value === '0' || display.value === 'Error' || display.value === 'HAPPY BIRTHDAY') {
202+
display.value = num;
203+
} else {
204+
display.value += num;
205+
}
206+
}
207+
208+
function appendOperator(operator) {
209+
display.value += operator;
210+
}
211+
212+
function clearDisplay() {
213+
display.value = '0';
214+
}
215+
216+
function deleteChar() {
217+
display.value = display.value.slice(0, -1) || '0';
218+
}
219+
220+
function calculate() {
221+
display.value = 'HAPPY BIRTHDAY';
222+
}
223+
224+
// Basic keyboard support
225+
document.addEventListener('keydown', (e) => {
226+
if (e.key >= '0' && e.key <= '9') appendNumber(e.key);
227+
if (e.key === '.') appendNumber('.');
228+
if ('+-*/'.includes(e.key)) appendOperator(e.key);
229+
if (e.key === 'Enter' || e.key === '=') calculate();
230+
if (e.key === 'Backspace') deleteChar();
231+
if (e.key === 'Escape') clearDisplay();
232+
});
182233
</script>
183234
</body>
184235
</html>

0 commit comments

Comments
 (0)