Finished for now - more information in the body!

New behaviour for 0 division, now multiple operations can be executed without pressing equals every operation, floating math reduced to 5, added using checks for numbers
This commit is contained in:
NetMan 2024-01-18 20:12:58 +01:00
parent 46a5c4e14c
commit 65ce64f08e
1 changed files with 25 additions and 5 deletions

View File

@ -15,6 +15,9 @@ function multiply(a, b) {
} }
function divide(a, b) { function divide(a, b) {
if (b == 0) {
return "Dividing by 0? That's illegal!";
}
return a / b; return a / b;
} }
@ -113,6 +116,11 @@ function handleOperators(value) {
if (operation.addToA) { if (operation.addToA) {
operation.operator = value; operation.operator = value;
} }
if (operation.readyForEquasion) {
execute(operation);
operation.addToA = !operation.addToA;
operation.operator = value;
}
operation.outputOfEquasion = false; operation.outputOfEquasion = false;
} }
@ -135,12 +143,20 @@ function clear() {
valueGui.textContent = operation.a; valueGui.textContent = operation.a;
} }
function populateDisplay(operation) { function display(operation) {
signGui.textContent = `${operation.operator}`; signGui.textContent = `${operation.operator}`;
if (operation.displayA) { if (operation.displayA) {
valueGui.textContent = `${operation.a}`; if (operation.a[operation.a.length - 1] == ".") {
valueGui.textContent = `${operation.a}`;
} else {
valueGui.textContent = `${Math.round(parseFloat(operation.a) * 100000) / 100000}`;
}
} else { } else {
valueGui.textContent = `${operation.b}`; if (operation.b[operation.b.length - 1] == ".") {
valueGui.textContent = `${operation.b}`;
} else {
valueGui.textContent = `${Math.round(parseFloat(operation.b) * 100000) / 100000}`;
}
} }
} }
@ -154,6 +170,9 @@ function handleAction(e) {
} }
let action = true; let action = true;
let passLetter = e.key.toLowerCase(); let passLetter = e.key.toLowerCase();
if (!checkNumber(operation.a) || !checkNumber(operation.b)) {
clear();
}
if (passLetter == " " if (passLetter == " "
|| passLetter == ".") { || passLetter == ".") {
addPoint(); addPoint();
@ -177,7 +196,8 @@ function handleAction(e) {
action = false; action = false;
} }
if (action) { if (action) {
populateDisplay(operation); display(operation);
e.preventDefault();
}; };
} }