Call calculator from dipslayToScreen
This commit is contained in:
parent
dc49e65560
commit
dce94d7165
1 changed files with 21 additions and 5 deletions
22
script.js
22
script.js
|
|
@ -9,7 +9,11 @@ buttons.forEach((button) => {
|
||||||
function displayToScreen() {
|
function displayToScreen() {
|
||||||
|
|
||||||
if (this.className == "equal") {
|
if (this.className == "equal") {
|
||||||
//equal
|
let calc = new Calculator;
|
||||||
|
|
||||||
|
console.log(screen.textContent)
|
||||||
|
screen.textContent = calc.calculate(screen.textContent) + " ";
|
||||||
|
console.log(typeof(screen.textContent))
|
||||||
} else if (this.className == "clear") {
|
} else if (this.className == "clear") {
|
||||||
//clear´
|
//clear´
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -24,14 +28,26 @@ function displayToScreen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (screen.textContent === "0") {
|
||||||
|
screen.textContent = this.textContent + " ";
|
||||||
|
console.log("A button was pressed");
|
||||||
|
} else {
|
||||||
|
screen.textContent += this.textContent + " ";
|
||||||
|
console.log("A button was pressed");
|
||||||
|
}
|
||||||
|
|
||||||
screen.textContent += this.textContent;
|
|
||||||
console.log("A button was pressed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function clear () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function Calculator(str) {
|
function Calculator(str) {
|
||||||
|
console.log("Calculator has been called")
|
||||||
|
|
||||||
this.methods = {
|
this.methods = {
|
||||||
"-": (a, b) => (a - b),
|
"-": (a, b) => (a - b),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue