-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (27 loc) · 900 Bytes
/
app.js
File metadata and controls
31 lines (27 loc) · 900 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
30
31
const calcDisplay = document.querySelector(".calc__screen");
const buttons = document.querySelectorAll("button");
const clearButton = document.getElementById("clear");
let calculation = [];
let accumulativeCalculation;
function calculate(button) {
const value = button.textContent;
if (value === "Clear") {
calculation = [];
calcDisplay.textContent = "";
console.clear();
} else if (value === "=") {
calcDisplay.textContent = eval(accumulativeCalculation);
console.log(accumulativeCalculation);
} else {
calculation.push(value);
accumulativeCalculation = calculation.join("");
accumulativeCalculation.toString();
calcDisplay.textContent = accumulativeCalculation;
}
}
buttons.forEach((button) =>
button.addEventListener("click", () => calculate(button))
);
// clearButton.addEventListener("click", () => {
// calcDisplay.textContent = "";
// });