Skip to content

Commit

Permalink
fixed divide by 0 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AirTechWick committed Sep 12, 2021
1 parent acf3ec3 commit 20f327c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ function divide(a,b)
if(b == 0)
{
window.alert("Nope, You can't do that!");
return;
secondNumber = 1;
activeOperator = "x"
result = operate(activeOperator,a,secondNumber);
displayValue = 1; // this somehow fixed it
return result;
}

result = a / b;
Expand Down Expand Up @@ -110,19 +114,22 @@ function deleteNumber()
function evaluate()
{
console.log("evaluate");

if(secondNumber == null)
{
secondNumber = displayValue;
console.log("secondNumber saved: ", secondNumber);
console.log("120secondNumber saved: ", secondNumber);
}


if(needNewSecondNumber)
{
secondNumber = displayValue;
console.log("secondNumber saved: ", secondNumber);
console.log("127secondNumber saved: ", secondNumber);
needNewSecondNumber = false;
}


operate(activeOperator,firstNumber,secondNumber);
displayResult();
}
Expand Down Expand Up @@ -179,7 +186,7 @@ function saveOperator(element)
else if(firstNumber != null)
{
secondNumber = displayValue;
console.log("secondNumber saved: ", secondNumber);
console.log("188secondNumber saved: ", secondNumber);
operate(activeOperator,firstNumber,secondNumber);
displayResult();
startNewDisplay = true;
Expand Down

0 comments on commit 20f327c

Please sign in to comment.