Remove comments/console messages/unused code and update clear error functionality
This commit is contained in:
parent
6fd432f906
commit
e8d3e81d68
1 changed files with 4 additions and 12 deletions
14
script.js
14
script.js
|
|
@ -31,7 +31,6 @@ function displayEval() {
|
||||||
result = calc.calculate(mainScreen.textContent);
|
result = calc.calculate(mainScreen.textContent);
|
||||||
} else {
|
} else {
|
||||||
topScreen.textContent += mainScreen.textContent;
|
topScreen.textContent += mainScreen.textContent;
|
||||||
console.log("main: " + mainScreen.textContent);
|
|
||||||
result = calc.calculate(topScreen.textContent);
|
result = calc.calculate(topScreen.textContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +45,6 @@ function displayOperator() {
|
||||||
let operator = this.textContent;
|
let operator = this.textContent;
|
||||||
|
|
||||||
if (operator == "-" && (isNaN(mainScreen.textContent) || mainScreen.textContent == "0")) {
|
if (operator == "-" && (isNaN(mainScreen.textContent) || mainScreen.textContent == "0")) {
|
||||||
console.log("Entering changeSign");
|
|
||||||
changeSign();
|
changeSign();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -89,11 +87,10 @@ function clear() {
|
||||||
topScreen.textContent = "";
|
topScreen.textContent = "";
|
||||||
|
|
||||||
} else if (this.classList.contains("error") && mainScreen.textContent !== "0") {
|
} else if (this.classList.contains("error") && mainScreen.textContent !== "0") {
|
||||||
mainScreen.textContent = mainScreen.textContent.trimEnd()
|
if (/^[0-9.]+$/.test(mainScreen.textContent)) {
|
||||||
mainScreen.textContent = mainScreen.textContent.slice(0, -1);
|
mainScreen.textContent = mainScreen.textContent.slice(0, -1);
|
||||||
|
} else {
|
||||||
if (!isNaN(mainScreen.textContent.charAt(-2))) {
|
mainScreen.textContent = "";
|
||||||
mainScreen.textContent = mainScreen.textContent.trimEnd()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainScreen.textContent === "") {
|
if (mainScreen.textContent === "") {
|
||||||
|
|
@ -107,16 +104,12 @@ function changeSign() {
|
||||||
let num = mainScreen.textContent;
|
let num = mainScreen.textContent;
|
||||||
|
|
||||||
if (num === "0") {
|
if (num === "0") {
|
||||||
// Replace 0 with the negative sign
|
|
||||||
mainScreen.textContent = "-";
|
mainScreen.textContent = "-";
|
||||||
} else if (num === "-") {
|
} else if (num === "-") {
|
||||||
// If already negative, reset to 0
|
|
||||||
mainScreen.textContent = "0";
|
mainScreen.textContent = "0";
|
||||||
} else if (num.startsWith("-")) {
|
} else if (num.startsWith("-")) {
|
||||||
// If the number is negative, remove the negative sign
|
|
||||||
mainScreen.textContent = num.substring(1);
|
mainScreen.textContent = num.substring(1);
|
||||||
} else {
|
} else {
|
||||||
// Toggle the sign for positive numbers
|
|
||||||
mainScreen.textContent = `-${num}`;
|
mainScreen.textContent = `-${num}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +156,6 @@ function divideDecimals(a, b) {
|
||||||
|
|
||||||
|
|
||||||
function Calculator(str) {
|
function Calculator(str) {
|
||||||
console.log("Calculator has been called")
|
|
||||||
isEval = true;
|
isEval = true;
|
||||||
|
|
||||||
this.methods = {
|
this.methods = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue