-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.js
More file actions
29 lines (24 loc) · 823 Bytes
/
Copy pathfirst.js
File metadata and controls
29 lines (24 loc) · 823 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
27
28
29
const buttons = document.querySelectorAll("button");
const display = document.querySelector(".display");
buttons.forEach((button) => {
button.addEventListener("click", () => {
const val = button.innerText;
switch (val) {
case "=":
try {
display.innerText = Function('"use strict";return (' + display.innerText + ')')();
} catch {
display.innerText = "Error";
}
break;
case "←":
display.innerText = display.innerText.slice(0, -1);
break;
case "C":
display.innerText = "";
break;
default:
display.innerText += val;
}
});
});