Level: Master of names, code does not pass


#1

Your hero doesn’t know these enemy’s names!

The glasses give you the findNearestEnemy ability.

enemy1 = self.findNearestEnemy()
self.attack(enemy1)
self.attack(enemy1)

enemy2 = self.findNearestEnemy()
self.attack(enemy2)
self.attack(enemy2)

enemy3 = self.findNearestEnemy()
self.attack(enemy3)
self.attack(enemy3)

Fix you code

Line 9: Target is null. Is there always a target to attack? (Use if?)

how is my code wrong?


#2

Your hero doesn’t know these enemy’s names!

The glasses give you the findNearestEnemy ability.

enemy1 = self.findNearestEnemy()
self.attack(enemy1)
self.attack(enemy1)

self.say(“Come Here”)
enemy2 = self.findNearestEnemy()
self.attack(enemy2)
self.attack(enemy2)

enemy3 = self.findNearestEnemy()
if enemy3:
self.attack(enemy3)
self.attack(enemy3)

i read some peoples code and found this to work.

How does it work for dude in the video with out adding an extra statement ???


#3

Hello, l0m1zzl3, and welcome. For future reference, please read the FAQ on how to properly format code.

Really, it all depends on how fast the munchkins are coming at you. Sometimes it works, sometimes it doesn’t.


#4

ok tks. i will read FAQ prior to my next post