|
116 | 116 | </div> |
117 | 117 | </div> |
118 | 118 |
|
| 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 | + |
119 | 127 | <script> |
| 128 | + /* |
| 129 | + // Original script (commented out) |
120 | 130 | const display = document.getElementById('display'); |
121 | 131 | let lastOperator = null; |
122 | 132 |
|
123 | | - // Load last saved value |
124 | 133 | document.addEventListener("DOMContentLoaded", () => { |
125 | 134 | display.value = localStorage.getItem('calcDisplay') || '0'; |
126 | 135 | }); |
|
169 | 178 | localStorage.setItem('calcDisplay', display.value); |
170 | 179 | } |
171 | 180 |
|
172 | | - // Keyboard support |
173 | 181 | document.addEventListener('keydown', (e) => { |
174 | 182 | if (e.key >= '0' && e.key <= '9') appendNumber(e.key); |
175 | 183 | if (e.key === '.' && !display.value.split(/[\+\-\*/]/).pop().includes('.')) appendNumber('.'); |
|
179 | 187 | if (e.key === 'Escape') clearDisplay(); |
180 | 188 | if (e.key === '%') appendOperator('%'); |
181 | 189 | }); |
| 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 | + }); |
182 | 233 | </script> |
183 | 234 | </body> |
184 | 235 | </html> |
0 commit comments