# Mad Maxer.... Again (Gets Greedy (Help))

In this level my hero does nothing, so I’m asking for help.(I didn’t know how to explain what my hero does but yeah).

here’s my code:

``````// Collect more coins than your doppelganger.
// You only have a few seconds to collect coins. Choose your path wisely!
while(true) {
var bestCoin = null;
var maxRating = 0;
var coinIndex = 0;
var coins = hero.findItems();
// Try calculating "value / distance" to decide which coins to get.
while (coins.value < 4) {
hero.moveXY(coin.pos.x,coin.pos.y);
}

}
``````
1 Like

That does not suppose to be in your code. First loop over each coin. After that try to put in a variabile called rating the coin.value/hero.distanceTo(coin) and then check if rating is bigger than maxRating and if that is the case, update the maxRating to rating and update bestCoin to coin. After you looped over all coins, then check if bestCoin exists and if so, moveXY to its position.

Andrei

1 Like

What??I’m confused???

1 Like

What do you not understand?

Andrei

1 Like

@Monsty, i have a good value over distance recipe:

``````bestCoin = None
gold = 3
silver = 2
bronze = 1
coinValue = gold or silver or bronze
minGoldDist = coinValue * 10
``````
1 Like

@Monsty do you still need help at this level or I mark this topic as solved?

1 Like

I still need help but you may help on all the others too but I’ll respond tomorrow.

The extra levels I did while I waited for someone to reply are 4 so I thought the 4 levels would be enough before tomorrow and then I have less work so I don’t need to do anything this Saturday. (I said this so you won’t ask “Then what’s the point of making them today”)

2 Likes

Ok then! See you tomorrow!

Andrei

1 Like

Hey I can help you. Why haven’t you looped through the array?

2 Likes

I dunno how to???

1 Like

You should probably go back and learn from previous levels. I’ll help you any way.

``````while (cookieIndex < cookies.length) {
``````
3 Likes

Okay @FalconX11_312 .

2 Likes

Remember,

``````practice = progress
``````

2 Likes

and

``````progress = greatness
``````

1 Like

Did you solve it? Remember to loop through the array.

2 Likes

No not yet. My dad told me to do Khan Academy then I have to do my homework.

1 Like