-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (30 loc) · 1.03 KB
/
script.js
File metadata and controls
31 lines (30 loc) · 1.03 KB
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
let string = "";
let buttons = document.querySelectorAll(".btn");
Array.from(buttons).forEach((button) => {
button.addEventListener("click", (e) => {
try {
if (e.target.innerHTML == "=") {
string = eval(string);
document.querySelector(".input").value = string;
} else if (e.target.innerHTML == "AC") {
string = "";
document.querySelector(".input").value = string;
} else if (e.target.innerHTML == "DE") {
if (string.length > 0 && string !== "Math Error") {
string = string.slice(0, string.length - 1);
document.querySelector(".input").value = string;
} else if (string === "Math Error") {
string = "";
document.querySelector(".input").value = string;
}
} else {
string = string + e.target.innerHTML;
document.querySelector(".input").value = string;
}
} catch (error) {
string = "";
string = string + `Math Error`;
document.querySelector(".input").value = string;
}
});
});