-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (21 loc) · 676 Bytes
/
script.js
File metadata and controls
24 lines (21 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Function to append numbers to the display
function appendNumber(number) {
document.getElementById('display').value += number;
}
// Function to append operators to the display
function appendOperator(operator) {
document.getElementById('display').value += operator;
}
// Function to clear the display
function clearDisplay() {
document.getElementById('display').value = '';
}
// Function to calculate the result
function calculate() {
try {
let result = eval(document.getElementById('display').value);
document.getElementById('display').value = result;
} catch (e) {
document.getElementById('display').value = 'Error';
}
}