So here’s the code I’m using;
enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)
enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
hero.say(distance2)
enemy3 = "Gorgnub"
distance3 = hero.distanceTo(enemy3)
hero.say(“distance3”)
yet the last enemy3 part of the code isn’t working and is firing at the cannon where the cannonball shoots out. I think this may be a bug, if not could anyone paste in a code that works?
Compare these lines:
hero.say(distance2) # works
# vs
hero.say(“distance3”) # doesn't work
It's always nice to format your code
Use ``` (these are backticks) before and after your code to format it.
Add blank lines between sections of your code to improve readability.
enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)
enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
hero.say(distance2)
enemy3 = "Gorgnub"
distance3 = hero.distanceTo(enemy3)
hero.say(“distance3”)
2 Likes