# \[SOLVED\] If else Problems, Help!

**URL:** <https://discourse.codecombat.com/t/solved-if-else-problems-help/1900>\
**Category:** Level Help\
**Created:** [December 15, 2014, 2:17am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900 "2014-12-15T02:17:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukebrannigan57](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lukebrannigan57/32/1873_2.png) [@lukebrannigan57](https://discourse.codecombat.com/u/lukebrannigan57)\
**Post date:** [December 15, 2014, 2:17am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/1 "2014-12-15T02:17:08Z")

</div>

This is just my latest permutation of code, I can’t get else statements to work, and keep getting this error, help!

---

<div class="post-metadata">

**Author:** ![dwhittaker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dwhittaker/32/2114_2.png) [@dwhittaker](https://discourse.codecombat.com/u/dwhittaker)\
**Post date:** [December 15, 2014, 2:19am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/2 "2014-12-15T02:19:23Z")

</div>

I’m going to need more to go on than this if I’m going to help you. Can you share what you have so far and the level you are working on. Be sure to use [code] tags to get your code looking pretty.

---

<div class="post-metadata">

**Author:** ![lukebrannigan57](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lukebrannigan57/32/1873_2.png) [@lukebrannigan57](https://discourse.codecombat.com/u/lukebrannigan57)\
**Post date:** [December 15, 2014, 2:20am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/3 "2014-12-15T02:20:49Z")

</div>

![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/1761/dc213535148ff580.png)

Sorry, I thought I enclosed a screenshot on that first post. New here, sorry.

---

<div class="post-metadata">

**Author:** ![dwhittaker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dwhittaker/32/2114_2.png) [@dwhittaker](https://discourse.codecombat.com/u/dwhittaker)\
**Post date:** [December 15, 2014, 2:24am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/4 "2014-12-15T02:24:55Z")

</div>

OK, so I see and extra ; in the middle of your if statements. if statements should not have semicolons.

Next, an else statement should be by itself with nothing else:

`else{`  
not  
`else enemy{`

---

<div class="post-metadata">

**Author:** ![lukebrannigan57](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lukebrannigan57/32/1873_2.png) [@lukebrannigan57](https://discourse.codecombat.com/u/lukebrannigan57)\
**Post date:** [December 15, 2014, 3:16am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/5 "2014-12-15T03:16:38Z")

</div>

Thanks. the page reloaded and I rewrote my code. This helped.

---

<div class="post-metadata">

**Author:** ![Damian\_ArchuletaMedi](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/damian_archuletamedi/32/11993_2.png) [@Damian\_ArchuletaMedi](https://discourse.codecombat.com/u/Damian_ArchuletaMedi)\
**Post date:** [April 25, 2020, 1:19am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/6 "2020-04-25T01:19:16Z")

</div>

im stuck on world two level 15b Backwoods Standoff B im really stuck becuase i used else statement and it does not work this is code:

while(true) {  
var enemy = hero.findNearestEnemy();  
if (hero.isready(“cleave”)) {  
hero.cleave(enemy);  
else {

{

}  
hero.attack(enemy);  
}  
}

i really dont know whats wrong

---

<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:** [April 25, 2020, 7:39am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/7 "2020-04-25T07:39:34Z")

</div>

HI @Damian_ArchuletaMedi, welcome to the codecombat discourse! 🎉  
Please could you format your code so I can see the indentations, here’s a topic explaining how to format:

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Thanks  
Danny

---

<div class="post-metadata">

**Author:** ![Carlos\_Delgado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/carlos_delgado/32/14640_2.png) [@Carlos\_Delgado](https://discourse.codecombat.com/u/Carlos_Delgado)\
**Post date:** [September 18, 2020, 3:19pm UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/8 "2020-09-18T15:19:36Z")

</div>

I am having troubles with my else statement, Its the backwoods standoff level, here is my code while True:  
enemy = hero.findNearestEnemy()  
# Use an if-statement with isReady to check “cleave”:  
if enemy:  
ready = hero.isReady(“cleave”)  
# Cleave!  
hero.cleave(enemy)  
else:  
hero.attack(enemy)

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [September 18, 2020, 3:28pm UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/9 "2020-09-18T15:28:55Z")

</div>

Welcome to the forum @Carlos_Delgado! 🥳  
Can you post your code as it says in this?  
And can you send me a link?

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Lydia

---

<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:** [September 18, 2020, 5:15pm UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/10 "2020-09-18T17:15:51Z")

</div>

Hi @Carlos_Delgado, it would be good to format your code as @Lydia_Song song said, but I can actually see the problem anyway.  
I’ve got a few questions from your code which might help you solve it. Does Cleave have a cooldown? Have you checked if your enemy is _ready_ to cleave? (remember you need a if statement to actually _check_ if something is true). When would the else actually run? (Look at what the if statement actually says: if enemy. When won’t there be an enemy? Never, so the else won’t run. Also inside the else statement, what if there isn’t an enemy? A lot of questions there…

Danny

---

<div class="post-metadata">

**Author:** ![Carlos\_Delgado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/carlos_delgado/32/14640_2.png) [@Carlos\_Delgado](https://discourse.codecombat.com/u/Carlos_Delgado)\
**Post date:** [September 18, 2020, 6:53pm UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/11 "2020-09-18T18:53:10Z")

</div>

I fixed it, it took me a bit of thinking, but I finally understand, I am learning how to code, and this is just one of my more, fun, ways of doing some learning.

---

<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:** [September 18, 2020, 6:56pm UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/12 "2020-09-18T18:56:59Z")

</div>

Nice. If you have any more troubles feel free to make another topic.  
Danny

---

<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:** [September 19, 2020, 6:57am UTC](https://discourse.codecombat.com/t/solved-if-else-problems-help/1900/13 "2020-09-19T06:57:14Z")

</div>

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