0

I'm trying to animate something, and I have this bit of code here:

Enemy.prototype.update = function () {
    var tx = 650 - this.x;
    var ty = 250 - this.y;
    var dist = Math.sqrt(tx * tx + ty * ty);
    this.velx = (tx / dist)* this.speed;
    this.vely = (ty / dist)* this.speed;
    var distround = Math.floor(dist);
    if (distround > 0) {
        this.x += this.velx;
        this.y += this.vely;
    } else if (this.transparency != 0){
      alert("You lose!");
      location.reload(true);
    }
};

I thought if I had the page refresh after the alert, it'd be okay, but sometimes there are a ton of alert boxes that pop up before it refreshes...how do I stop this? The full code is here: (warning, multiple alerts will be triggered...best not to use safari to open) http://jsfiddle.net/nLxLpvry/

imhappi
  • 125
  • 1
  • 8
  • 1
    This is a good example why using `alert()` for debugging is a bad idea. See http://stackoverflow.com/questions/4539253/what-is-console-log – JJJ Apr 20 '15 at 07:56

1 Answers1

1

This is because every enemy has an update method that calls the alert. So when all the enemies disappear all the enemies call their alert which results in many many alert messages being displayed.

Adi
  • 5,560
  • 1
  • 24
  • 37