Possible bug on sarven-sheperd(or it`s just a code problem anyway, help!)

loop {
    var enemies = this.findEnemies();
    var enemyIndex = 0;
    // Wrap this logic in a while loop to attack all enemies.
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        
        // "!=" means "not equal to."
        if (enemy.type != "sand-yak") {
            // While the enemy's health is greater than 0, attack it!
            while (enemy.health > 0) {
                this.attack(enemy);
            }
                
        }
        enemyIndex = enemyIndex + 1;
    }
    // Between waves, move back to the center.
    this.moveXY(39, 32);
}

I think the codes are all right but it tells me “unreachable while after return”

and on the shine getter, I coded

loop {
    var coins = this.findItems();
    var coinIndex = 0;
    // Wrap this into a loop that iterates over all coins.
    while (coinIndex < coins.length){
        var coin = coins[coinIndex];
        // Gold coins are worth 3.
        if (coin.value == 3) {
            // Only pick up gold coins.
            var posg = coin.pos;
            var gx= posg.x;
            var gy= posg.y;
            this.moveXY(gx, gy);
        }
        coinIndex++;
    }
}

this, but it also tells me "unreachable while after return"
Is anything wrong with my code? or is it a bug?

Your code works fine. Did you already try to run these levels in other browsers?


1 Like