# Sarven Shepherd infinite loop (Javascript)

**URL:** <https://discourse.codecombat.com/t/sarven-shepherd-infinite-loop-javascript/10156>\
**Category:** Uncategorized\
**Created:** [January 2, 2017, 9:41am UTC](https://discourse.codecombat.com/t/sarven-shepherd-infinite-loop-javascript/10156 "2017-01-02T09:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marvelous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marvelous/32/5499_2.png) [@Marvelous](https://discourse.codecombat.com/u/Marvelous)\
**Post date:** [January 2, 2017, 9:41am UTC](https://discourse.codecombat.com/t/sarven-shepherd-infinite-loop-javascript/10156/1 "2017-01-02T09:41:18Z")

</div>

I’m having a problem with Sarven Shepherd level, as it’s throwing me a infinite loop error and the character just stands still. I think it’s because it is looping on the first Yak… and I’m not sure how to remedy this.

```
while(enemyIndex < enemies.length) {
    var enemy = enemies[enemyIndex];
    if (enemy.type != "sand-yak") {
        while(enemy.heath > 0) { // If I comment this
            hero.attack(enemy);
        } // & this, it works..
    }
enemyIndex++;
}

```

But when I remove `while(enemy.heath > 0)` and the curly brackets around attack, it seems to run fine, abit kind of funky as they hit the enemies a few times and run back to the X, etc. 761 health doesn’t seem to be enough health for this level.

I tried looking at other similar threads, but they don’t seem to help with the looping, and I dunno how I feel about necroing an old thread.

---

<div class="post-metadata">

**Author:** ![Ty\_Ler](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ty_ler/32/5322_2.png) [@Ty\_Ler](https://discourse.codecombat.com/u/Ty_Ler)\
**Post date:** [January 2, 2017, 11:16am UTC](https://discourse.codecombat.com/t/sarven-shepherd-infinite-loop-javascript/10156/2 "2017-01-02T11:16:45Z")

</div>

Its your spelling. Try enemy.health. You for got the L.

Im surprised the error didnt tell you “heath” isnt a method of enemy. Normally it would give a suggestion did you mean health? At least from my experience it has.

---

<div class="post-metadata">

**Author:** ![Marvelous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marvelous/32/5499_2.png) [@Marvelous](https://discourse.codecombat.com/u/Marvelous)\
**Post date:** [January 2, 2017, 12:26pm UTC](https://discourse.codecombat.com/t/sarven-shepherd-infinite-loop-javascript/10156/3 "2017-01-02T12:26:22Z")

</div>

Oh wow, I didn’t catch that. lol  
Yea it would of been helpful if it did threw an error about “heath”.
