Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help! I've done everything Brittle Morale asked!

It says that enemy is not defined, but then when I try to define it, it still has an error.

# You have one arrow. Make it count!

# This should return the enemy with the most health.
def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    # While enemyIndex is less than the length of enemies:
    while enemyIndex < len(enemies):
        # Set an enemy variable to enemies[enemyIndex]
        enemy == enemies[enemyIndex]
        # If enemy.health is greater than strongestHealth
        if enemy.health > strognestHealth:
            # Set `strongest` to enemy
            strognest == enemy
            # Set strongestHealth to enemy.health
            strognestHealth == enemy.health
        # Increment enemyIndex
        enemyIndex += 1
    
    return strongest

enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
    hero.say(leader)

You are using enemy==enemies[enemyIndex] instead of enemy=enemies[enemyIndex]. == checks if values are equal, and = makes values equal.

Hi, welcome to the CodeCombat discourse.
You have two problems:

  1. the one which @xantar mentioned
    and
  2. a typo of strongest. You’ve written strognest three times here:
if enemy.health > strognestHealth:
    # Set `strongest` to enemy
    strognest == enemy
    # Set strongestHealth to enemy.health
    strognestHealth == enemy.health

Danny