javascript - JS NaN after array[index] -


i started programming js again , having trouble. can't afford lose more time, thought maybe more eyes can find problem. it's gonna simple calculator web browsers. same code other buttons(0-9)

sum = 0;  var actual = new array(0);  var counter = 0;  function button1pressed(){  if(counter==0){     actual.push(1);     counter=1;      sum=actual[0]; }else{     actual.push(1); //insert new number          counter=counter*10;     for(i = actual.length; > 0; i--){         sum = sum + actual[i] * counter;     }    } document.getelementbyid("display").innerhtml = sum; sum = 0; } 

what did wrong?

start loop actual.length-1, because every array starts 0, last element actual.length-1 not actual.length.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -