so i'm javascript beginner , i'm working on making calculator. right i'm testing out addition button i'm having troubles code on equal button. code button :
function equalpress() { storednumbertwo = document.getelementbyid("output").innerhtml; // if(sign === 1) { calc = +storednumbertwo + +storednumber; document.getelementbyid("output").innerhtml = calc; // } }
i've commented out if statement show i've done sort of working. when don't use if statement can equals sign add , work properly, however, not going work when i'm adding in other operators. sign variable going use switch operator pressed 1= +, 2 = -, etc... anyways when add if statement in can test see operator pressed whole calculator freezes , can't press buttons. i'm not sure why happening, i've tried using switch instead of if statements , i've used various types of variables condition , hasn't worked. appreciated. here fiddle. https://jsfiddle.net/rk1mu4rb/3/
don't use var
access variables declared in outer scope. var
keyword inside function creates new variable local function, hiding other variables same name defined outside.
i've updated fiddle , removed var
part sign = 1
: https://jsfiddle.net/rk1mu4rb/4/
Comments
Post a Comment