-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
27 lines (23 loc) · 817 Bytes
/
app.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
const screenDisplay = document.querySelector(".screen");
const buttons = document.querySelectorAll("button");
let calculation = [];
let accumulativeCalculation;
localStorage.getItem(JSON.stringify("calculation"));
function calculate(button) {
const value = button.textContent;
if (value === "CLEAR") {
calculation = [];
screenDisplay.textContent = ".";
} else if (value === "=") {
screenDisplay.textContent =
Math.round(eval(accumulativeCalculation) * 100) / 100;
JSON.parse(localStorage.setItem("calculation", accumulativeCalculation));
} else {
calculation.push(value);
accumulativeCalculation = calculation.join("");
screenDisplay.textContent = accumulativeCalculation;
}
}
buttons.forEach((button) =>
button.addEventListener("click", () => calculate(button)),
);