# Summit's gate (js)

**URL:** <https://discourse.codecombat.com/t/summits-gate-js/31507>\
**Category:** Level Help\
**Created:** [December 5, 2021, 11:55am UTC](https://discourse.codecombat.com/t/summits-gate-js/31507 "2021-12-05T11:55:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![foxfire](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/foxfire/32/13755_2.png) [@foxfire](https://discourse.codecombat.com/u/foxfire)\
**Post date:** [December 5, 2021, 11:55am UTC](https://discourse.codecombat.com/t/summits-gate-js/31507/1 "2021-12-05T11:55:42Z")

</div>

hi,  
I made this code for the first part of the level, but the hero & friends don’t move and let the enemy attack them.  
can you please help me find my mistake? Thanks!

```python
function findEnemy(){
    var oof = ["fangriders","throwers","ogres","scouts","munchkins"];
    for(var e =0;e<oof.length;e++){
        var currentEnemy = oof[e];
        if (currentEnemy.length > 0) {
            return currentEnemy;
            }
        else {continue;}
        }
}
function unitsAttack(){
    var friends = hero.findFriends();
    for(var u =0; u<friends.length;u++){
        var unit = friends[u];
            var toAttack = unit.findNearest(findEnemy());
           if (toAttack) {
            hero.command(unit, "attack", toAttack);
            }
              }
}
while(true) {
    unitsAttack();
    var toAttack = hero.findNearest(findEnemy());
    if (toAttack) {
        hero.attack(toAttack);
    }
}

```

---

<div class="post-metadata">

**Author:** ![riticmaster908](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/riticmaster908/32/43503_2.png) [@riticmaster908](https://discourse.codecombat.com/u/riticmaster908)\
**Post date:** [December 5, 2021, 10:48pm UTC](https://discourse.codecombat.com/t/summits-gate-js/31507/2 "2021-12-05T22:48:09Z")

</div>

> [@foxfire](#):
>
> `["fangriders","throwers","ogres","scouts","munchkins"];`

what if the enemy type is not here? (like shamans and skeles and warlock (for end phase) ) try doin EVERY TYPE of enemy in the game that are in summits gate.
