-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (23 loc) · 758 Bytes
/
script.js
File metadata and controls
26 lines (23 loc) · 758 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
25
26
const display = document.getElementById("display");
const buttons = document.querySelectorAll("button");
let currentInput = "";
buttons.forEach(button => {
button.addEventListener("click", () => {
const value = button.textContent;
if (value === "C") {
currentInput = "";
display.value = "";
} else if (value === "=") {
try {
currentInput = eval(currentInput).toString();
display.value = currentInput;
} catch (err) {
display.value = "Error";
currentInput = "";
}
} else {
currentInput += value;
display.value = currentInput;
}
});
});