-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
38 lines (33 loc) · 848 Bytes
/
script.js
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
// Display screen
let result = document.getElementById('result');
// Append number to the screen
function appendValue(value) {
result.value += value;
}
// Append operators (like +, -, *, /)
function appendOperator(operator) {
if (operator === 'pi') {
result.value += Math.PI;
} else if (operator === 'e') {
result.value += Math.E;
} else {
result.value += operator;
}
}
// Calculate the result
function calculate() {
try {
result.value = eval(result.value.replace('^', '**'));
} catch (error) {
alert("Invalid Input");
clearScreen();
}
}
// Clear the screen
function clearScreen() {
result.value = "";
}
// Delete the last character from the screen
function deleteLast() {
result.value = result.value.slice(0, -1);
}