# Help for noobs (mainly me)

**URL:** <https://discourse.codecombat.com/t/help-for-noobs-mainly-me/1108>\
**Category:** Uncategorized\
**Created:** [September 9, 2014, 9:12pm UTC](https://discourse.codecombat.com/t/help-for-noobs-mainly-me/1108 "2014-09-09T21:12:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [September 9, 2014, 9:12pm UTC](https://discourse.codecombat.com/t/help-for-noobs-mainly-me/1108/1 "2014-09-09T21:12:32Z")

</div>

So i am new to CodeCombat and the tutorial did nothing to help me in multiplayer so i have been doing the best i can to figure out how to wright and use the different codes/spells. Anyway so I use the guide in dungeon battle or whatever and use this code:

```javascript
this.findTypeInRange = function(units, type) {
    for (var i = 0; 1 < units.length; ++i) {
        var unit = units[i];
        if (unit.type === type && this.distance(unit) < this.attackRange)
            return unit;
    }
    return null;
};
var enemies = this.getEnemies();
for(var i = 0; i < enemies.length; ++i) {
  var enemy = enemies[i];
}
var shaman = this.findTypeInRange(enemies, "shaman");
var brawler = this.findTypeInRange(enemies, "brawler");
var munchkin = this.findTypeInRange(enemies, "munchkin");
var thrower = this.findTypeInRange(enemies, "thrower", "spear"); 

```

and when i do the cast spell (btw this is on tharin) it says could not define ‘type’ and in the guide this is almost exactly how its written except for a couple of things. And i do not know how to define ‘type’ cause its nowhere in the guide and when i go the ‘type’ spell in the bottom all it says is this.type-string or something like that. So i need help if any of you veterens gan give me tips or help me with the problem at hand that would be very helpful thanks

---

<div class="post-metadata">

**Author:** ![WizardDude](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wizarddude/32/1516_2.png) [@WizardDude](https://discourse.codecombat.com/u/WizardDude)\
**Post date:** [September 10, 2014, 12:07pm UTC](https://discourse.codecombat.com/t/help-for-noobs-mainly-me/1108/2 "2014-09-10T12:07:41Z")

</div>

In the body of your function you have:

```
for (var i = 0; 1 < units.length; ++i) {

```

The condition `1 < units.length` will always be true if `units` has more than one item. This will cause you to run over the end of the array. This probably means that `unit` ends up as `undefined`, so when you try to access `unit.type`, it blows up.

You probably meant to use `i` here.

I couldn’t see anything else obvious that would prevent your code from running but I just eyeballed it.

Happy dungeoneering!

---

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [September 10, 2014, 8:29pm UTC](https://discourse.codecombat.com/t/help-for-noobs-mainly-me/1108/3 "2014-09-10T20:29:14Z")

</div>

thanks it worked ill probably be back with more problems but this really helps
