Keeping time in javascript


#1

Hey guys,

I also need some help in this level. I don’t know why I always failing in one seconds by said “your hero must survive. (1/2)”. Who is the other? what s going on???

This is what I have.


//Commented out to stop infinite loop.
// Use your new skill to choose what to do: this.now()
loop {
    // If it's the first 10 seconds, fight.
    var enemy = this.findNearestEnemy();
    var item = this.findNearestItem();
    
    if (this.now() < 10) {
        if(this.isReady("cleave")){
            this.cleave(enemy);
            }
        else {
            this.attack(enemy);
    }
    if(this.now() > 12){
                this.say("I know! Geez relax. ");
            }
    }
    else if(this.now() < 35){
            if(item) {
                var pos = item.pos;
                var x = pos.x;
                var y = pos.y;
                this.moveXY(x, y);
            }
            }
            
    if (this.now() > 30){
        if(enemy){
        if(this.isReady("cleave")){
            this.cleave(enemy);
            }
        else {
            this.attack(enemy);
            }
        }
    }

}




#2

you have on the left hand side a Friend, who should also survive. Look at him, maybe he dies because you havnt killed enemys.
Second: Try only to cleave when the enemy is in range. So if(isReady) and (distanceTo<=10)
Third: what does your hero do between 10 and 12 Seconds? I think your this.now() >12 should be a < …