0

I wanna move my button to bottom with a couple of codes here :

var y = [];
for(var i = 0;i < 8;i++){
   y[i] = 0;
   interval[i] = setInterval(function(){
      y[i]++;
      if(parseInt(y[i]) >= window.innerHeight){
          clearInterval(this);
      }
      console.log(y[i]);
      thisbutton.style.top = y[i] + "px";
   },10);
}

My problem is that y[i] is NaN.
Can you tell me why?
thanks

  • unfortunately no my problem is not running function my problem is that the variable is NaN always:( – Alireza932 Apr 28 '22 at 19:47
  • what does for of mean? – Alireza932 Apr 28 '22 at 19:49
  • You see in the duplicate that if you have `var i` declared in the `for` loop, then *the actual value of `i` would only be one* at the end. And it's going to be `i = 9`. Your array will have 8 items, getting the 9th item from an array of 8 will give you `undefined`. Incrementing `undefined` produces `NaN`. – VLAZ Apr 28 '22 at 19:53

0 Answers0