-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (30 loc) · 898 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
28
29
30
31
32
import Calculator from "./calculator.js";
const primaryOperationDisplay = document.querySelector(
"[data-primary-operand]"
);
const secondaryOperationDisplay = document.querySelector(
"[data-secondary-operand]"
);
const operationDisplay = document.querySelector("[data-operation]");
const calculator = new Calculator(
primaryOperationDisplay,
secondaryOperationDisplay,
operationDisplay
);
document.addEventListener("click", (e) => {
if (e.target.matches("[data-all-clear]")) {
calculator.clear();
}
if (e.target.matches("[data-number]")) {
calculator.addDigit(e.target.textContent);
}
if (e.target.matches("[data-delete]")) {
calculator.removeDigit();
}
if (e.target.matches("[data-operation]")) {
calculator.chooseOperation(e.target.textContent);
}
if (e.target.matches("[data-equals]")) {
calculator.evaluate();
}
});