[SOLVED] How to use setInterval

I cant seem to understand on how to use SetInterval(). Can anyone please explain it to me what i’m am doing wrong

Ghost.prototype.update = function(dt) {
    var timer = 0;
    var start = start;
    function swicher(){
        switch(timer){
                case(1): timer=0;
                break;
                case(0): timer=1;
                break;
            default: break;
        }
    }
    //1=left, 0=Right
    if(timer===1){
        this.entity.translate(-1*dt,-1*dt,0);
    } else{
        this.entity.translate(1*dt,-1*dt,0);
    }
      var timesss=  setInterval(swicher(),100);
};

There are a few things. The largest of which is that you are creating a new setInterval every time update is called. If you are running at 60fps, you have then created 60 setInterval calls which are calling the swicher function every 100ms.

TBH, I wouldn’t use setInterval at all.

Ghost.prototype.initialize = function() {
  this.leftSide = false;
  this.secsSinceLastFlip = 0f;
}


Ghost.prototype.update = function(dt) {
  if (this.secsSinceLastFlip > 100) {
    this.leftSide = !this.leftSide;
    this.secsSinceLastFlip = 0f;
  }

  if(this.leftSide){
    this.entity.translate(-1*dt,-1*dt,0);
  } else{
    this.entity.translate(1*dt,-1*dt,0);
  }

  this.secsSinceLastFlip += dt;
}

i keep forgeting that dt goes of every second

Not quite. the update function gets called every frame and the dt being passed the is number of seconds since the last update frame (usually 0.01666666 secs if running at 60fps (1/60)).