Help with CodeCombat Challenge: The One Wizard


#1

Hello. I’m trying to get all the bonuses for The One Wizard Challenge, but I can only defeat 17 ogres with the code below:

while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        if (hero.canCast("chain-lightning")) {
            hero.cast("chain-lightning", enemy);
        }
        else if (hero.canCast("lightning-bolt")) {
            hero.cast("lightning-bolt", enemy);
        }
        else {
            hero.attack(enemy);
        }
    }
    if (hero.health < 50 && hero.canCast("regen")) {
        hero.cast("regen", hero);
    }
}

I read somewhere about using certain spells depending on enemy type, so I modified the code I wrote above as can be seen below:

while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        if (enemy.type == "scout" || enemy.type == "munchkin" && hero.canCast("chain-lightning")) {
            hero.cast("chain-lightning", enemy);
        }
        else if (enemy.type == "catapult" || enemy.type == "ogre" && hero.canCast("lightning-bolt")) {
            hero.cast("lightning-bolt", enemy);
        }
        else {
            hero.attack(enemy);
        }
    }
    if (hero.health < 50 && hero.canCast("regen")) {
        hero.cast("regen", hero);
    }
}

I’m not getting any errors with either of the codes. But I still can’t get all the bonuses (defeat 44 ogres). Does anyone have any idea what’s wrong with either of these codes? Thanks.


#2

You just have to have better code. There is no answer to this. I don’t code JS, so I don’t know what’s going on with it. There is nothing wrong with either of the codes. It means you have to come back when you have better coding skills-no offense. :rice_ball::neutral_face::neutral_face: