Level: Molotov Medic

I can’t seem to figure out how to beat this level?! In the for-loop, how do you determine how much health any troop has? Thanks for the help!

Hello! Each troop has a health property, so you just need to append .health to the end of their objects to access their health.

For example, to get Tharin’s health, you would use this.health, and if you have an object named friend, you would use friend.health

Keep in mind, though, that this particular level is kind of broken, and might not behave exactly the way you think it will.

this was a great hint. THis seems to work for me:

var friends = this.getFriends();
for ( i=1; i < friends.length; ++i ) {
var friend = friends[i];
if(friend.health < 15 ) {
this.say("Here, " + friend.id + “!”);
this.attack(friend);
}
}

Good job! That’s pretty similar to my code.

One thing you may want to consider doing is trying to determine who needs the potion the most and then giving the potion to them, instead of always waiting until someone gets below 15

yes - haven’t figured that piece out yet. thanks!

My first code was like this:

var friends = this.getFriends();    
for (var i = 0; i < friends.length; i++) {
     if(friends[i].health < 10) {
        this.say("Here, " + friends[i].id + "!");
        this.attack(friends[i]);
     }
}

It didnt work so I checked the forums and its pretty much the same as @michael_bubb 's code. But it still doesnt work for me :slight_smile: I tried to change the health to 15 as michael, but it still didnt work. Is there a better way to do this or the level is just bugged?

//////

I had previously beaten that level, and now the code I used (which is basically what you’re using) isn’t working, so I think something must have changed, like the attack speed of the brawler or something.

I did make some tweaks to that level after I noticed that the balance had gotten a bit off. I think in order to beat it now, you’ll have to find the friend with the least health, not just the last one who has health < 10.