# Protect And Serve help! please!

**URL:** <https://discourse.codecombat.com/t/protect-and-serve-help-please/35766>\
**Category:** Level Help\
**Created:** [June 22, 2023, 9:42pm UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766 "2023-06-22T21:42:15Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [June 22, 2023, 9:42pm UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766/1 "2023-06-22T21:42:15Z")

</div>

I don’t know what’s wrong with my code. 😭 this is what it looks like

```python
// Protect the workers and animals!

// Defend these two positions:
let defend = [];
defend[0] = {x: 98,y: 28};
defend[1] = {x: 84,y: 7};
let soldiers = [];
let friends = hero.findFriends();
for (let i = 0; i < friends.length; i++) {
   let friend = friends[i];
   if (friend.type == "soldier") {
       soldiers.push(friend);
   } else {
// Defend the workers:
       defend.push(friend);
   }
}
while (true) {
   // Use a for-loop to assign each soldier to a corresponding defend[] target
   // Use command(soldier, "defend", thang) or command(soldier, "defend", position)
   for (let friend of friends) {
if (friend.type == "soldier" || friend.type == "archer") {
hero.command(friend, "defend", defend[1]);
       }
   }
}

```

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [June 23, 2023, 8:20am UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766/2 "2023-06-23T08:20:17Z")

</div>

(deleted - I forgot that indentation doesn’t matter in JS)

---

<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:** [June 23, 2023, 1:36pm UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766/3 "2023-06-23T13:36:39Z")

</div>

I don’t know what indentation means. 🤨

---

<div class="post-metadata">

**Author:** ![James\_Pfiffner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/james_pfiffner/32/22991_2.png) [@James\_Pfiffner](https://discourse.codecombat.com/u/James_Pfiffner)\
**Post date:** [June 23, 2023, 5:43pm UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766/4 "2023-06-23T17:43:21Z")

</div>

I’m sorry I can’t help. I only know python ☹

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [June 24, 2023, 11:14pm UTC](https://discourse.codecombat.com/t/protect-and-serve-help-please/35766/5 "2023-06-24T23:14:49Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
