# Whats wrong with my code?

**URL:** <https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883>\
**Category:** Level Help\
**Created:** [April 9, 2020, 1:32am UTC](https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883 "2020-04-09T01:32:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon60079414](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon60079414](https://discourse.codecombat.com/u/anon60079414)\
**Post date:** [April 9, 2020, 1:32am UTC](https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883/1 "2020-04-09T01:32:41Z")

</div>

```
enemy = hero.findNearestEnemy()
if enemy:
    hero.attack(enemy)
else:
    hero.bash(enemy)
if hero.isReady("cleave"):
    hero.cleave(enemy)
else:
    hero.electrocute(enemy)
```

---

<div class="post-metadata">

**Author:** ![hello\_there](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hello_there/32/11810_2.png) [@hello\_there](https://discourse.codecombat.com/u/hello_there)\
**Post date:** [April 9, 2020, 7:01am UTC](https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883/2 "2020-04-09T07:01:03Z")

</div>

before you bash use hero.isReady

---

<div class="post-metadata">

**Author:** ![hello\_there](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hello_there/32/11810_2.png) [@hello\_there](https://discourse.codecombat.com/u/hello_there)\
**Post date:** [April 9, 2020, 7:01am UTC](https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883/3 "2020-04-09T07:01:34Z")

</div>

use hero.isReady on hero.electrocute as well

---

<div class="post-metadata">

**Author:** ![hello\_there](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hello_there/32/11810_2.png) [@hello\_there](https://discourse.codecombat.com/u/hello_there)\
**Post date:** [April 9, 2020, 7:05am UTC](https://discourse.codecombat.com/t/whats-wrong-with-my-code/20883/4 "2020-04-09T07:05:22Z")

</div>

wait a minute, how can you bash when there’s no enemy
