Help with Mad Maxer Code

Yes, I did…but see how you have your while set up? It’s still referencing ‘enemy’…it is still part of the attack code, so to speak.

So what do I do with the while loop?

@dedreous The instructions tell me to add a while loop that checks if the enemies health is greater than 0

Let’s see if this helps…here’s an outline of your code:

  • Figure out which enemy is the farthest away
    • While looking through all enemies, find the one that is farthest
    • Once you have the farthest enemy, define it as the object ‘target’
  • If you’ve found farthest
    • while its health is greater than zero
    • beat the heck out of it!

There is no ‘enemy’ in the second part of your code, only ‘farthest’.

@dedreous so what am I supposed to add

I figured out what I was doing wrong. I just had to attack enemy in the while loop and bfore the loop I had to attack the farthest. Thanks a lot for the help @dedreous

not add, change…notice that I said there was no ‘enemy’ in your second code block, only ‘farthest’. Here is your second block of code:

    if (farthest) {
        // Take out the farthest enemy!
        // Keep attacking the enemy while its health is greater than 0.
        while(enemy.health>0) {
            hero.attack(farthest);
        }
    }

I see an ‘enemy’ there still :wink:

How do I add [Solved] to the title

You can edit the title, or on the post you feel helped most, click on the checkbox that should be showing down by the Reply, Edit, etc icons…lower right of an individual post within the topic thread.

@dedreous How do I edit the title… If I click the title it just refreshes the page

If you scroll up to the first post, do you see something like this? This icon will let you edit the title:

However, by selecting the checkbox as you did, this topic is already marked as solved…thanks!

By the way I don’t see anything like that pencil… I can only click on the title

Ok…it might be that you are still at Basic User. With more time and more posts, replies, etc, this will change.

oh OK, Thanks for the help though… I cant believe that I didn’t figure that sooner

@dedreous And also I cant see the [Solved] at the top of this topic

YAY u solved the problem

We’ve talked about posting on old topics. Please don’t do it. Use the like button instead.
Thanks
Danny

aw man i did that again(sorry danny)

1 Like

It’s alright, you haven’t been on the Discourse that long, I’m sure you’ll get used to the rules soon :grin:
Danny

ok great i look forword to being a better user