Add space before and after operator
This commit is contained in:
parent
b23ce98b4e
commit
a7fd6ca4e5
1 changed files with 14 additions and 19 deletions
31
script.js
31
script.js
|
|
@ -6,45 +6,40 @@ buttons.forEach((button) => {
|
||||||
button.addEventListener ("click", displayToScreen);
|
button.addEventListener ("click", displayToScreen);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function displayToScreen() {
|
function displayToScreen() {
|
||||||
|
|
||||||
if (this.className == "equal") {
|
if (this.className == "equal") {
|
||||||
let calc = new Calculator;
|
let calc = new Calculator;
|
||||||
|
|
||||||
console.log(screen.textContent)
|
console.log(screen.textContent)
|
||||||
screen.textContent = calc.calculate(screen.textContent) + " ";
|
screen.textContent = calc.calculate(screen.textContent);
|
||||||
} else if (this.className == "clear") {
|
} else if (this.className == "clear") {
|
||||||
//clear´
|
screen.textContent = "0";
|
||||||
} else {
|
} else {
|
||||||
let screenContent = screen.textContent;
|
let screenContent = screen.textContent;
|
||||||
|
|
||||||
if (this.className == "operator") {
|
if (this.className == "operator") {
|
||||||
|
screen.textContent += " ";
|
||||||
|
|
||||||
for (let i = 0; i < screenContent.length; i++ ) {
|
for (let i = 0; i < screenContent.length; i++ ) {
|
||||||
if (operators.includes(screenContent[i])) {
|
if (operators.includes(screenContent[i])) {
|
||||||
let calc = new Calculator;
|
let calc = new Calculator;
|
||||||
|
|
||||||
console.log(screen.textContent)
|
console.log(screen.textContent);
|
||||||
screen.textContent = calc.calculate(screen.textContent) + " ";
|
result = calc.calculate(screen.textContent);
|
||||||
console.log("An operator was pressed again")
|
screen.textContent += result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (screen.textContent === "0") {
|
|
||||||
screen.textContent = this.textContent + " ";
|
|
||||||
console.log("A button was pressed");
|
|
||||||
} else {
|
|
||||||
screen.textContent += this.textContent + " ";
|
screen.textContent += this.textContent + " ";
|
||||||
console.log("A button was pressed");
|
} else if (screen.textContent === "0" && this.className == "num") {
|
||||||
|
screen.textContent = this.textContent;
|
||||||
|
} else {
|
||||||
|
screen.textContent += this.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function clear () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue