Hunting Party Help -- Javascript

I am stuck on the level Hunting Party. Whenever I run my code, it sends the soldiers and archers forwards, but then they just stay there. It says their action is “move”, but I can’t figure out why and/or where thay are moving! Here is my code:

var friends = hero.findFriends();
for(var i = 0; i < friends.length; i++){
var friend = friends[i];
hero.command(friend, “move”, {x:friend.pos.x + 35, y:friend.pos.y});
}
var enemy = friend.findNearestEnemy();
for(var f = 0; f < friends.length; f++){
var friend = friends[f];
if(enemy) {
hero.command(friend, “attack”, enemy);
}
}

Please format your code according to the FAQ

From what i can see, i think that this line

should be after the friend definition inside the for loop, so the for loop should be like this

for(var f = 0; f < friends.length; f++){
    var friend = friends[f];
    var enemy = friend.findNearestEnemy();
    if(enemy) {
        hero.command(friend, “attack”, enemy);
    }
}

Sorry about that. I forgot my password after a year.

1 Like

Thank you! I took a few more hours and worked through it!

1 Like