I'm new to coding and I am making a javascript game. In this game, I want to spawn enemies every 5 seconds or so. I have created an enemy class and tried to make an if statement that creates a new enemy every 5 seconds(300 frames in my case).

`if(framect % 300 === 0) new enemy();`

Here is my enemy class

```

var plusOrMinus = Math.random() < 0.5 ? -1 : 1;
espd =  plusOrMinus*Math.random()*13;

class enemy{
  constructor(){
    this.x =  Math.random() * window.innerWidth;
    this.y= Math.random() * window.innerHeight;
    this.xspd = espd;
    this.yspd = espd;
    this.size= 12;
    objects.push(this);
  }
  step(){
    this.x += this.xspd;
    this.y += this.yspd;

  }
  draw(){
    strokeColor(255, 0, 0);
    fillColor(255,0,0);
    circle(this.x,this.y,this.size);
  }
}

```

When I attempt this it creates just one enemy. I know as I have a list of objects and there is only one enemy that shows up in the list. How would I do this?

I'm pretty sure its not a problem with framect as it increases with every frame. Here is how I went about doing the framecount and game loop.

```
function loop(){
  stepLoop();
  drawLoop();
  keyEnd();

}

function stepLoop(){
  for (var i = 0; i<objects.length; i++) {
    if(objects[i].step) objects[i].step();
    framect++;
  }
}
function drawLoop(){
  background(25, 25, 25);
  for (var i = 0; i<objects.length; i++) {
    if(objects[i].draw) objects[i].draw();
  }
  hero.draw();
}
var target_fps = 60;
setInterval(loop, 1000/target_fps);

```