Move initial calculations to top screen
This commit is contained in:
parent
92629c81fe
commit
61a3c3b929
2 changed files with 11 additions and 7 deletions
11
script.js
11
script.js
|
|
@ -1,4 +1,5 @@
|
||||||
const mainScreen = document.querySelector(".main-screen");
|
const mainScreen = document.querySelector(".main-screen");
|
||||||
|
const topScreen = document.querySelector(".top-screen");
|
||||||
const buttons = document.querySelectorAll("button");
|
const buttons = document.querySelectorAll("button");
|
||||||
const operators = ["+", "-", "*", "/"];
|
const operators = ["+", "-", "*", "/"];
|
||||||
|
|
||||||
|
|
@ -10,8 +11,9 @@ buttons.forEach((button) => {
|
||||||
function displayToScreen() {
|
function displayToScreen() {
|
||||||
if (this.className == "equal") {
|
if (this.className == "equal") {
|
||||||
let calc = new Calculator;
|
let calc = new Calculator;
|
||||||
|
topScreen.textContent += mainScreen.textContent;
|
||||||
|
|
||||||
mainScreen.textContent = calc.calculate(mainScreen.textContent);
|
mainScreen.textContent = calc.calculate(topScreen.textContent);
|
||||||
} else if (this.classList.contains("all")) {
|
} else if (this.classList.contains("all")) {
|
||||||
mainScreen.textContent = "0";
|
mainScreen.textContent = "0";
|
||||||
} else if (this.classList.contains("error") && mainScreen.textContent !== "0") {
|
} else if (this.classList.contains("error") && mainScreen.textContent !== "0") {
|
||||||
|
|
@ -27,7 +29,7 @@ function displayToScreen() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.className == "operator") {
|
if (this.className == "operator") {
|
||||||
let screenContent = mainScreen.textContent;
|
let screenContent = topScreen.textContent;
|
||||||
|
|
||||||
// Add some logic for handling negatives with -
|
// Add some logic for handling negatives with -
|
||||||
// Add key support
|
// Add key support
|
||||||
|
|
@ -37,13 +39,14 @@ function displayToScreen() {
|
||||||
if (operators.includes(screenContent[i])) {
|
if (operators.includes(screenContent[i])) {
|
||||||
let calc = new Calculator;
|
let calc = new Calculator;
|
||||||
|
|
||||||
result = calc.calculate(mainScreen.textContent);
|
result = calc.calculate(topScreen.textContent);
|
||||||
mainScreen.textContent = result;
|
mainScreen.textContent = result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainScreen.textContent += " " + this.textContent + " ";
|
topScreen.textContent += mainScreen.textContent + " " + this.textContent + " ";
|
||||||
|
mainScreen.textContent = "0";
|
||||||
|
|
||||||
} else if (mainScreen.textContent === "0" && this.className == "num") {
|
} else if (mainScreen.textContent === "0" && this.className == "num") {
|
||||||
mainScreen.textContent = this.textContent;
|
mainScreen.textContent = this.textContent;
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,16 @@ main {
|
||||||
background: #eee;
|
background: #eee;
|
||||||
color: #111;
|
color: #111;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
font-size: 80px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
.top-screen {
|
.top-screen {
|
||||||
height: 20%;
|
height: 40%;
|
||||||
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
.main-screen {
|
.main-screen {
|
||||||
height: 80%;
|
height: 60%;
|
||||||
|
font-size: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue