[Solved]Help with vision of ogres

Why does it say TypeError: Cannot read property ‘0’ undifined.

# Destroy a real ogre and illusions will disappear.

def findRealEnemy(enemies):
    for index in range(len(enemies)):
        enemy = enemies[index]
        # Convert the enemy's name (id) to lower case
        # and save it in a variable.
        name = enemy.id
        lowerCase = name.toLowerCase()
        # Split the name by whitespaces and save the words.
        words = lowerCase.split()
        # Store the second word in a variable.
        secondWord = words[1]
        # If the first letter of the second word equals to
        # the last letter of that word.
        if secondWord[0] == secondWord[len(secondWord)-1]:
            # Then it's the real one. Return the enemy.
            return enemy
# Only attack real ogres.
while True:
    ogres = hero.findEnemies()
    realOgre = findRealEnemy(ogres)
    if realOgre:
        while realOgre.health > 0:
            hero.attack(realOgre)

You have

        # Split the name by whitespaces and save the words.
        words = lowerCase.split()

and in the hints:

 words = someStr.split(separator) # To get an array of words;

What is your separator?

2 Likes

Thanks for the help!