if/else statement keeps running wrong function

I think you swapped which button should set the Equals button's value attribute and which should clear it.

I think you could make this easier to catch by naming things more consistently. For example, you could change the names from postfix and infix to orderPemdas and orderLeftToRight. Then, set the Equals button's value attribute to either orderPemdas or orderLeftToRight, as appropriate. This would make it much easier to understand what's going on in the handleEverything function without having to remember context from the button event listeners.

To understand what was happening, I wrote this simplified pseudocode showing the logic we care about in your code as written.

when postFixBtn ("Order of operations") is clicked:
  set equalsBtn value to '='

when inFixBtn ("Calculate as written") is clicked:
  delete equalsBtn's value attribute

when equalsBtn is clicked:
  if equalsBtn has value attribute (per above, postFixBtn has been clicked):
    run handleInfix function
  else (per above, inFixBtn has been clicked):
    run handleCalculate function

Let me know if that helps!

/r/learnjavascript Thread