# Need help on CodeCombat- Sarven Shepherd

**URL:** <https://discourse.codecombat.com/t/need-help-on-codecombat-sarven-shepherd/6590>\
**Category:** Uncategorized\
**Created:** [January 26, 2016, 8:54pm UTC](https://discourse.codecombat.com/t/need-help-on-codecombat-sarven-shepherd/6590 "2016-01-26T20:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeWarrior729](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@CodeWarrior729](https://discourse.codecombat.com/u/CodeWarrior729)\
**Post date:** [January 26, 2016, 8:54pm UTC](https://discourse.codecombat.com/t/need-help-on-codecombat-sarven-shepherd/6590/1 "2016-01-26T20:54:51Z")

</div>

I’m trying to beat Sarven Shepherd and I’m using JavaScript. Here is my code: loop {  
var enemies = this.findEnemies();  
var enemyIndex = 0;

```
    // Wrap this logic in a while loop to attack all enemies.
    // Find the array's length with: enemies.length
while (enemyIndex < enemies.length) {
    var enemy = enemies[enemyIndex];
    // "!=" means "not equal to."
    if (enemy.type != "sand-yak") {
        while (health > 0) {
        this.attack(enemy);      
        }
        enemyIndex += 1;
    }

    
}
// Between waves, move back to the center.
this.moveXY(40,32);
}
```

---

<div class="post-metadata">

**Author:** ![Luke10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/luke10/32/19892_2.png) [@Luke10](https://discourse.codecombat.com/u/Luke10)\
**Post date:** [January 27, 2016, 12:19am UTC](https://discourse.codecombat.com/t/need-help-on-codecombat-sarven-shepherd/6590/2 "2016-01-27T00:19:07Z")

</div>

Can you please give a little bit more information? Does it say anything like “error on line 2” or ‘‘fix you code’’?

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [January 27, 2016, 1:17am UTC](https://discourse.codecombat.com/t/need-help-on-codecombat-sarven-shepherd/6590/3 "2016-01-27T01:17:11Z")

</div>

If _enemies[enemyIndex_] is _sand-yak_, you will never get into the **if** so you will never increment enemyIndex.

You’ll find a sand-yank, see that it is a sand-yak, then go again through the loop and find the same yak again.

Move the enemyIndex+=1; out of the **if** after the if closing bracket **}**  
By the way _add one_ is such an used structure that it has an even short version:

```python
enemyIndex++;

```
