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/
 
    