# Hunting Party (JavaScript) Question

**URL:** <https://discourse.codecombat.com/t/hunting-party-javascript-question/5173>\
**Category:** Uncategorized\
**Created:** [October 7, 2015, 8:03pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173 "2015-10-07T20:03:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hokie007](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@Hokie007](https://discourse.codecombat.com/u/Hokie007)\
**Post date:** [October 7, 2015, 8:03pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173/1 "2015-10-07T20:03:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [October 7, 2015, 11:44pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173/2 "2015-10-07T23:44:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hokie007](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@Hokie007](https://discourse.codecombat.com/u/Hokie007)\
**Post date:** [October 8, 2015, 1:23pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173/3 "2015-10-08T13:23:05Z")

</div>

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.

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/9/9dd47134ac0f2cf00d24421e1a7e734c65f21552.jpg)

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [October 8, 2015, 2:28pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173/4 "2015-10-08T14:28:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hokie007](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@Hokie007](https://discourse.codecombat.com/u/Hokie007)\
**Post date:** [October 8, 2015, 2:49pm UTC](https://discourse.codecombat.com/t/hunting-party-javascript-question/5173/5 "2015-10-08T14:49:31Z")

</div>

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.
