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:
parent
46a5c4e14c
commit
65ce64f08e
30
script.js
30
script.js
|
@ -15,6 +15,9 @@ function multiply(a, b) {
|
|||
}
|
||||
|
||||
function divide(a, b) {
|
||||
if (b == 0) {
|
||||
return "Dividing by 0? That's illegal!";
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
|
||||
|
@ -113,6 +116,11 @@ function handleOperators(value) {
|
|||
if (operation.addToA) {
|
||||
operation.operator = value;
|
||||
}
|
||||
if (operation.readyForEquasion) {
|
||||
execute(operation);
|
||||
operation.addToA = !operation.addToA;
|
||||
operation.operator = value;
|
||||
}
|
||||
operation.outputOfEquasion = false;
|
||||
}
|
||||
|
||||
|
@ -135,12 +143,20 @@ function clear() {
|
|||
valueGui.textContent = operation.a;
|
||||
}
|
||||
|
||||
function populateDisplay(operation) {
|
||||
function display(operation) {
|
||||
signGui.textContent = `${operation.operator}`;
|
||||
if (operation.displayA) {
|
||||
valueGui.textContent = `${operation.a}`;
|
||||
} else {
|
||||
valueGui.textContent = `${operation.b}`;
|
||||
if (operation.a[operation.a.length - 1] == ".") {
|
||||
valueGui.textContent = `${operation.a}`;
|
||||
} else {
|
||||
valueGui.textContent = `${Math.round(parseFloat(operation.a) * 100000) / 100000}`;
|
||||
}
|
||||
} else {
|
||||
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 passLetter = e.key.toLowerCase();
|
||||
if (!checkNumber(operation.a) || !checkNumber(operation.b)) {
|
||||
clear();
|
||||
}
|
||||
if (passLetter == " "
|
||||
|| passLetter == ".") {
|
||||
addPoint();
|
||||
|
@ -177,7 +196,8 @@ function handleAction(e) {
|
|||
action = false;
|
||||
}
|
||||
if (action) {
|
||||
populateDisplay(operation);
|
||||
display(operation);
|
||||
e.preventDefault();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue