# Computer science 2, level 26

**URL:** <https://discourse.codecombat.com/t/computer-science-2-level-26/21680>\
**Category:** Level Help\
**Created:** [May 20, 2020, 12:55am UTC](https://discourse.codecombat.com/t/computer-science-2-level-26/21680 "2020-05-20T00:55:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daneisys\_F](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/daneisys_f/32/12293_2.png) [@Daneisys\_F](https://discourse.codecombat.com/u/Daneisys_F)\
**Post date:** [May 20, 2020, 12:55am UTC](https://discourse.codecombat.com/t/computer-science-2-level-26/21680/1 "2020-05-20T00:55:53Z")

</div>

```python
// Peons are trying to steal your coins!
// Write a function to squash them before they can take your coins.

function pickUpCoin() {
    var coin = hero.findNearestItem();
    if(coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
}

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!

while(true) {
    //attackEnemy(); // ∆ Uncomment this line after you write an attackEnemy function.
    pickUpCoin();
}

```

---

<div class="post-metadata">

**Author:** ![EpicCoder999](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/epiccoder999/32/12768_2.png) [@EpicCoder999](https://discourse.codecombat.com/u/EpicCoder999)\
**Post date:** [May 20, 2020, 12:58am UTC](https://discourse.codecombat.com/t/computer-science-2-level-26/21680/2 "2020-05-20T00:58:50Z")

</div>

sry bro im not a sub

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [May 20, 2020, 7:50am UTC](https://discourse.codecombat.com/t/computer-science-2-level-26/21680/3 "2020-05-20T07:50:38Z")

</div>

You need to write the attackEnemy function. Use the pickUpCoin function as a template.
