jeudi 1 septembre 2016

Why does my javascript not work when I use an if statement in my function

so I'm a javascript beginner and I'm working on making a calculator. Right now I'm just testing out my addition button but I'm having troubles with the code on the equal button. the code for the button is :

  function equalPress() {

  storedNumberTwo = document.getElementById("output").innerHTML;
  // if(sign === 1) {
  calc = +storedNumberTwo + +storedNumber;
  document.getElementById("output").innerHTML = calc;
  // }
  }

I've commented out the if statement to show what I've done to sort of get it working. When I don't use the if statement I can get the equals sign to add and work properly, however, this is obviously not going to work well when I'm adding in the other operators. The sign variable is what I was going to use as a switch for which operator was pressed 1= +, 2 = -, etc... Anyways when I add the if statement in so that I can test to see which operator was pressed the whole calculator freezes up and I can't press any buttons. I'm not sure why this is happening, I've tried using switch instead of if statements and I've used various types of variables for my condition and it hasn't worked. Any help would be appreciated. here is my fiddle. http://ift.tt/2bIKrtC

Aucun commentaire:

Enregistrer un commentaire