-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (32 loc) · 907 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
let previousContent = '';
let currentContent = '';
let operator = null;
const previousContentDisplay = document.getElementById('previous-content');
const currentContentDisplay = document.getElementById('current-content');
function updateDisplay() {
previousContentDisplay.innerText = previousContent;
currentContentDisplay.innerText = currentContent;
}
function clearDisplay() {
previousContent = '';
currentContent = '';
operator = null;
updateDisplay();
}
function deleteLast() {
currentContent = currentContent.slice(0, -1) || '';
updateDisplay();
}
function appendCharacter(char) {
currentContent += char;
updateDisplay();
}
function calculateResult() {
try {
previousContent = currentContent + ' =';
currentContent = eval(currentContent).toString();
} catch (error) {
currentContent = 'Error';
}
updateDisplay();
}