Help with CodeCombat Challenge: The One Wizard

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.

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:

Try if/else
Or elif

Don’t comment on something that was 2 years ago.

Hello and welcome to codecombat discourse, @Windpillar! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

@Freya wont need help anymore since this was 2 years ago, but if you need help on this level you can ask for help even if the last post was 2 years ago. Does that make any sense?