-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (22 loc) · 774 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
const resultsDisplay = document.querySelector(".display > .content")
const keys = document.querySelector(".keys")
keys.addEventListener("click", (event) => {
let target = event.target
if (target.className.includes("digit") || target.className.includes("operator")) {
let keyValue = target.textContent
if (keyValue === "=") {
let operation_string = resultsDisplay.textContent
let calculation_results = calculator(operation_string)
resultsDisplay.textContent = `${calculation_results}`
}
else if (keyValue === "C") {
resultsDisplay.textContent = ""
}
else {
resultsDisplay.textContent += keyValue
}
}
})
function calculator(operationString) {
return eval(operationString)
}