# Village Wander helppp! (javascript)

**URL:** https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445
**Category:** Level Help
**Created:** [May 6, 2020, 7:48pm UTC](https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445 "2020-05-06T19:48:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![freshkid006](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/freshkid006/32/12127_2.png) [@freshkid006](https://discourse.codecombat.com/u/freshkid006)
#### Post date: [May 6, 2020, 7:48pm UTC](https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445/1 "2020-05-06T19:48:53Z")

</div>

When I run this code, my hero does not attack the orgs. The orgs continue to go to the villager and attacks them. Can someone help me with this problem?

}  
}

// Define a function to cleave enemies (but only when the ability is ready).  
function findAndCleaveEnemy() {  
// Find the nearest enemy:  
var enemy = hero.findNearestEnemy();  
// If an enemy exists:  
if (enemy) {

```
}
    // And if "cleave" is ready:
    var ready = hero.isReady("cleave");
        // It's time to cleave!
        hero.cleave(enemy);

```

}

// In your main loop, patrol, cleave, and attack.  
while (true) {  
// Move to the patrol point, cleave, and attack.  
hero.moveXY(35, 34);  
findAndCleaveEnemy();  
findAndAttackEnemy();

```
// Move to the other point:
hero.moveXY(60, 31);
// Use findAndCleaveEnemy function:
findAndCleaveEnemy();
// Use findAndAttackEnemy function:
findAndAttackEnemy();

```

}

---

<div class="post-metadata">

### Author: ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)
#### Post date: [May 7, 2020, 9:49am UTC](https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445/2 "2020-05-07T09:49:05Z")

</div>

Please could you fully format your code. Put ```javascript on a single line before your code then three backticks after your code.  
Thanks

---

<div class="post-metadata">

### Author: ![freshkid006](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/freshkid006/32/12127_2.png) [@freshkid006](https://discourse.codecombat.com/u/freshkid006)
#### Post date: [May 7, 2020, 6:45pm UTC](https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445/3 "2020-05-07T18:45:03Z")

</div>

It doesn’t matter anymore my teacher told me the answer✅

---

<div class="post-metadata">

### Author: ![freshkid006](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/freshkid006/32/12127_2.png) [@freshkid006](https://discourse.codecombat.com/u/freshkid006)
#### Post date: [May 7, 2020, 7:14pm UTC](https://discourse.codecombat.com/t/village-wander-helppp-javascript/21445/4 "2020-05-07T19:14:36Z")

</div>

but thanks for the help
