# Kithgard Brawl 2 in Javascript: findEnemies Not Working (Bug or Feature?)

**URL:** <https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669>\
**Category:** Bugs\
**Created:** [August 11, 2015, 2:29am UTC](https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669 "2015-08-11T02:29:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JTorero](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jtorero/32/2911_2.png) [@JTorero](https://discourse.codecombat.com/u/JTorero)\
**Post date:** [August 11, 2015, 2:29am UTC](https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669/1 "2015-08-11T02:29:19Z")

</div>

In Kithgard Brawl, I am not able to use “findEnemies” even though that ability is granted by the Fine Telephoto Lenses.

With the following code, the hero never says anything.

```python
loop {
    var enemies = this.findEnemies();
    if (enemies) {
        this.say(enemies);
    }
}

```

The code works if I use “findNearestEnemy”, and the hero says the enemy’s name.

```python
loop {
    var enemy = this.findNearestEnemy();
    if (enemy) {
        this.say(enemy);
    }
}

```

Is this a bug, or is the findEnemies method blocked for this challenge? (It worked in Kithgard Brawl 1).

---

<div class="post-metadata">

**Author:** ![trotod](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/trotod/32/3263_2.png) [@trotod](https://discourse.codecombat.com/u/trotod)\
**Post date:** [August 11, 2015, 4:33am UTC](https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669/2 "2015-08-11T04:33:26Z")

</div>

An array is always truthy (at least in JavaScript), regardless of how many elements it has, which is why your `if` condition runs. `this.say` works by converting the argument into a string (`'' + []` becomes `''`). The hero apparently doesn’t say anything when the string is empty. So when there are no enemies, the array is empty, so the string value is `''`, and the hero doesn’t say anything. If there were enemies your hero would say something like `"Grot,Brak,Treg"`, etc.

Now, if there were actually enemies and your hero isn’t saying anything, that’s a problem.

You could try fixing this by checking `enemies.length`. `0` evaluates to `false`.

However, It would be nice to see something that indicates that there’s a value (especially since `null` and `undefined` cause problems when sometimes I just want to test if something is `null`/`undefined`).

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [August 11, 2015, 2:53pm UTC](https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669/3 "2015-08-11T14:53:31Z")

</div>

Good idea. I’ve changed it so that saying an empty array or object now show `[]` or `{}`.

---

<div class="post-metadata">

**Author:** ![JTorero](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jtorero/32/2911_2.png) [@JTorero](https://discourse.codecombat.com/u/JTorero)\
**Post date:** [August 11, 2015, 5:07pm UTC](https://discourse.codecombat.com/t/kithgard-brawl-2-in-javascript-findenemies-not-working-bug-or-feature/4669/4 "2015-08-11T17:07:18Z")

</div>

Great explanation! Thank you!
