Spaces:
No application file
No application file
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Function to append the clicked button value to the display
|
| 2 |
+
function appendToDisplay(value) {
|
| 3 |
+
document.getElementById('display').value += value;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
// Function to clear the display
|
| 7 |
+
function clearDisplay() {
|
| 8 |
+
document.getElementById('display').value = '';
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// Function to calculate the result of the expression in the display
|
| 12 |
+
function calculateResult() {
|
| 13 |
+
try {
|
| 14 |
+
let result = eval(document.getElementById('display').value);
|
| 15 |
+
document.getElementById('display').value = result;
|
| 16 |
+
} catch (error) {
|
| 17 |
+
document.getElementById('display').value = 'Error';
|
| 18 |
+
}
|
| 19 |
+
}
|