Weakest Quickest - code not working


#1

I’m on Weakest Quickest in the desert, and I’m getting an error message that a variable I can see I set doesn’t exist. Maybe there’s something I’m not getting, so I’ll post it for the general public to debug:

I thought that maybe I needed enemy = weakest towards the top of the screenshot, but that didn’t work either.


#2
weakest = findWeakestEnemy()

#3

@RobAnybody Even though the function ends with return weakest?

(I’d just test it, but I’m in the middle of some rather intense coding in a different level right now.)


#4

I can’t see the rest of the code, but I am assuming that var weakest is only defined, and used inside of the function above. If true, as far as I know, variables that are used within functions are ‘trapped’ and cannot be called from outside of the function itself. When you’re returning ‘weakest’ you are actually just returning a value, not the actual variable. You might need to post the rest of the code, but you should try:

hero.attack(findWeakestEnemy())

#5

I ended up using @RobAnybody 's code, just because the text editor prompted you to break it up with an extra line, but it looks like @Skillster 's would be a more concise version of the same thing.


#6

I was having fits with this.
I got it to work without the function so I knew I was on the right track but I wanted to do it as a function since that’s the part of the lesson.
The problem / solution isn’t line 25 or line 17 but because line 23 is part of the original text/code we assume it doesn’t need modification.


#7

i did it with my own code hahaha
click here for help.


#8

Please do not post solutions because they let users just wanting to beat the level just copy off without learning anything.


#9

Ok, but you must be subscriber for it to work