# hero.findEnemies() Quiz

**URL:** <https://discourse.codecombat.com/t/hero-findenemies-quiz/17873>\
**Category:** Uncategorized\
**Created:** [March 16, 2019, 9:36pm UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873 "2019-03-16T21:36:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [March 16, 2019, 9:36pm UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873/1 "2019-03-16T21:36:39Z")

</div>

You have the following piece of code:  
java script:

```python
var enemies = hero.findEnemies();
if (enemies)
    hero.say('So many enemies!');
else
    hero.say('No enemies!');

```

or python:

```python
enemies = hero.findEnemies()
if enemies:
    hero.say('So many enemies!')
else:
    hero.say('No enemies!')

```

**What will hero say if there are no enemies?**

You can test the it in [https://codecombat.com/play/level/logical-path](https://codecombat.com/play/level/logical-path)? for python or  
in [https://codecombat.com/play/level/logical-path?codeLanguage=javascript](https://codecombat.com/play/level/logical-path?codeLanguage=javascript) for java script.  
You don’t need to be logged in, no glasses needed for hero.findEnemies() in any level in codecombat.  
Simply comment the default ( or your ) code and paste the above code.

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [March 16, 2019, 10:52pm UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873/2 "2019-03-16T22:52:07Z")

</div>

The hero will say “So many enemies!”, since the enemies array exists, even if there are no enemies

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [March 16, 2019, 11:12pm UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873/3 "2019-03-16T23:12:46Z")

</div>

And how the code must be rewritten to work as intended? ( question not to @SuperSmacker , I know he knows the answer 😉 )

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [March 17, 2019, 12:57am UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873/4 "2019-03-17T00:57:48Z")

</div>

The easiest way I can think of (python)…

> **Spoiler alert**
>
> Instead of: `if enemies:`,
> 
> change to: `if len(enemies) > 0:`

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [March 17, 2019, 8:37pm UTC](https://discourse.codecombat.com/t/hero-findenemies-quiz/17873/5 "2019-03-17T20:37:33Z")

</div>

Yes, this is the way this check must be done. ( if enemies.length \> 0: will also work in CoCo python )  
I have made a search in topics and there are many examples where this error is present. But the catch is the CoCo python isn’t acting as a real python.  
If there are no enemies the answer must be **‘No enemies!’**  **after if enemies:** in real python.  
see [Enemy = Null, filter confusingly functioning (Solved)](https://discourse.codecombat.com/t/enemy-null-filter-confusingly-functioning-solved/8420/4?u=xython)
