Hunting Party (JavaScript) Question

Hello. I am stuck and confused by the level “Hunting Party”. The commented header portion states:

// Use for-loops and findFriends.
// You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.

I need to have glasses equipped that have both of the functions of findFriends() and findNearestEnemy(). Unless I am missing something, there are no glasses that have both of these functions present. Thus, I can either choose glasses that have the findFriends() function that allows for the array of friendly units to be constructed. Or I can wear glasses that have findNearestEnemy so I can identify the nearest enemy, however, I want the friends to be able to identify the enemy after I have identified the array of friends and issued them move commands via the for loop. I am wondering what glasses or methods those of you who have passed this level used.

You only need glasses with this.findFriends(). Friends have seeing abilities of their own. Just use enemy = friend.findNearestEnemy();.

Thanks for the response. However, that suggestion does not work, as I get a “not a function” error message. I am wearing the Twilight (Red) Glasses.

Huh. Interesting. In your for-loop, you are adding one to the list friends, not to friendIndex. That could possibly explain the problem.

1 Like

Good catch. Interestingly, that was the entire issue. Changed it to increment friendIndex instead of the erroneously incrementing the “friends” array. The “not a function” error was no longer present, allowing successful completion of the level. Thanks for your input and assistance.

1 Like