[SOLVED] CodeCombat - Coding games to learn Python and JavaScript


HELP ME PLEASE…I’ve been trying to figure out how to do this…I’ve tried many different codes from many different people but the only thing that happens is either the hero dies after fighting for the longest time or he doesn’t even move…I am a student and cant seem to figure out the problem…I just want someone who can explain this to me
Heres My Code:

Use while loops to pick out the ogre

while True:
enemies = hero.findEnemies()
enemyIndex = 0
for enemy in enemies:
hero.attack(enemy)

# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with:  len(enemies)

enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
    # While the enemy's health is greater than 0, attack it!
    
    pass

# Between waves, move back to the center.

You have to either commit to using a for loop, or a while loop. At the moment you’re trying to use both.

and:

You’re not incrementing enemyIndex so “enemy” will never change. I recommend using a while loop. If you can’t remember how to do it you can look back at older levels.

1 Like

oh my goodness thank you so much :slight_smile: