# Help for Steelclaw Gap \[javascript\]

**URL:** <https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804>\
**Category:** Uncategorized\
**Created:** [March 6, 2017, 2:54pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804 "2017-03-06T14:54:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Afuldye](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/afuldye/32/5608_2.png) [@Afuldye](https://discourse.codecombat.com/u/Afuldye)\
**Post date:** [March 6, 2017, 2:54pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/1 "2017-03-06T14:54:10Z")

</div>

hello, I need help for [steelclaw gap](https://codecombat.com/play/level/steelclaw-gap)

I thought I did everything like explained, but I must have missed something. I keep getting an error when I try to command to defend. (see screenshot below).  
Thank you for any clue. 😉

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/7/7a67a1a9dfd96fcc7e379682c47011eb0e2343c5.jpg)

My code is here:

```python
// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

var defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}];

var summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"];

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
function summonTroops() {
    var type = summonTypes[hero.built.length % summonTypes.length];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for(var friendIndex=0; friendIndex < friends.length; friendIndex++) {
        var friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        var point = defendPoints[friendIndex.length % defendPoints.length];
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", point);
    }
}

while(true) {
    summonTroops();
    commandTroops();
}

```

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [March 6, 2017, 4:15pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/2 "2017-03-06T16:15:34Z")

</div>

Post in FAQ. I believe it is asking that point needs to be x , y coordinates, and when doing the equation for point, you did not receive a valid value. A way to check is by having the hero say the variable “point”. Could you please post what the answer was?

---

<div class="post-metadata">

**Author:** ![Afuldye](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/afuldye/32/5608_2.png) [@Afuldye](https://discourse.codecombat.com/u/Afuldye)\
**Post date:** [March 6, 2017, 6:14pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/3 "2017-03-06T18:14:36Z")

</div>

It’s blank… so it seems point is not even calculated… I don’t understand what I did wrong 😕

---

<div class="post-metadata">

**Author:** ![htrnblr](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@htrnblr](https://discourse.codecombat.com/u/htrnblr)\
**Post date:** [March 6, 2017, 6:31pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/4 "2017-03-06T18:31:54Z")

</div>

```python
var point = defendPoints[friendIndex % defendPoints.length];

```

friendIndex have no length

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [March 6, 2017, 8:16pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/5 "2017-03-06T20:16:03Z")

</div>

@htrnblr Nice Catch! You said that friendindex was a number not an array, so there is no length

---

<div class="post-metadata">

**Author:** ![Afuldye](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/afuldye/32/5608_2.png) [@Afuldye](https://discourse.codecombat.com/u/Afuldye)\
**Post date:** [March 6, 2017, 9:07pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/6 "2017-03-06T21:07:04Z")

</div>

😁😁😁 You did it! thanks a lot!

---

<div class="post-metadata">

**Author:** ![catkitty123](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@catkitty123](https://discourse.codecombat.com/u/catkitty123)\
**Post date:** [December 6, 2018, 1:50am UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/7 "2018-12-06T01:50:10Z")

</div>

Hi there, I don’t like to do this, but I really need help: Nothing’s working!!!  
No errors, but all my soldiers/archers keep dying.  
I beg you, please help!

```python
// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

var defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}];

var summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"];

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
function summonTroops() {
    var type = summonTypes[hero.built.length % summonTypes.length];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for(var friendIndex=0; friendIndex < friends.length; friendIndex++) {
        var friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        hero.command(friend, "defend", defendPoints[friendIndex % 4]);
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints[friendIndex % 4]);
        }
}

while(true) {
    summonTroops();
    commandTroops();
}

```

---

<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:** [December 6, 2018, 6:11am UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/8 "2018-12-06T06:11:45Z")

</div>

Why do you need two identical lines of code in commandTroops()? Try first only with a single one.

---

<div class="post-metadata">

**Author:** ![catkitty123](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@catkitty123](https://discourse.codecombat.com/u/catkitty123)\
**Post date:** [December 9, 2018, 8:09pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/9 "2018-12-09T20:09:58Z")

</div>

Nope, not working.  
Thanks anyway…

---

<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:** [December 9, 2018, 9:27pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/10 "2018-12-09T21:27:08Z")

</div>

What happens? You are losing one warrior?

---

<div class="post-metadata">

**Author:** ![milescombat](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milescombat/32/34822_2.png) [@milescombat](https://discourse.codecombat.com/u/milescombat)\
**Post date:** [August 27, 2023, 6:27pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/11 "2023-08-27T18:27:21Z")

</div>

I also need help with this level. I’m not sure what to put where my code says HELP!

```python
let defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}];
let summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"];
function summonTroops() {
    let type = summonTypes[hero.built.length % summonTypes.length];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}
function commandTroops() {
    let friends = hero.findFriends();
    for(let friendIndex=0; friendIndex < friends.length; friendIndex++) {
        let friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        HELP!
        defendPoints % friendIndex;
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints);
    }
}
while(true) {
    summonTroops();
    commandTroops();
}

```

---

<div class="post-metadata">

**Author:** ![milescombat](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milescombat/32/34822_2.png) [@milescombat](https://discourse.codecombat.com/u/milescombat)\
**Post date:** [August 27, 2023, 6:28pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/12 "2023-08-27T18:28:50Z")

</div>

pls pls pls _please_ help!

---

<div class="post-metadata">

**Author:** ![gnarlyMarley](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/gnarlymarley/32/34823_2.png) [@gnarlyMarley](https://discourse.codecombat.com/u/gnarlyMarley)\
**Post date:** [September 3, 2023, 3:11pm UTC](https://discourse.codecombat.com/t/help-for-steelclaw-gap-javascript/10804/13 "2023-09-03T15:11:12Z")

</div>

Re-enter the level and carefully read the Goals, especially the last line.

You need to pick a single object from defendPoints, then use it as an argument in hero.command().
