Diamond Dozen problem

Hi! I have a problem with my code in Diamond Dozen level. I spent some hours on this level and still I can’t figure out my problem. Below I put an image with my code. Please help me!

Problem is with finding highest item.value / hero.distanceTo(item) from my items array, I don’t know what I am doing wrong so if anyone have any idea and can help me I will appreciate it

could you copy your code because it’s really hard to read the pic.

Yeah, sure

function valueOverDistance(item) {
    return item.value / hero.distanceTo(item);
// Return the item with the highest valueOverDistance(item)
function findBestItem(items) {
    var bestItem = null;
    var bestValue = 0;
    var itemsIndex = 0;

    // Loop over the items array.
    // Find the item with the highest valueOverDistance()
    while (itemsIndex < items.length) {
        var item = items[itemsIndex];
        var highest = valueOverDistance(item);
        if (highest > bestValue) {
            bestValue = highest;
            bestItem = item;
    return bestItem;

The problem is with finding the highest valueOverDistance from my array of items, this should find the highest one and return bestItem, and then collect it, but it doesn’t work.

This is very useful code for replayable treasure levels. You can get more coins more quickly than hero.findNearestItem():wink:

Yeah I like it but still I don’t know what am I doing wrong. Maybe you have any idea?

Hi, can you send us an email at team@codecombat.com and reference this forum post?

I think there may be something wrong with the level itself, but can’t be sure unless I can get your session.

Yeah I’m having the EXACT same problem! I HATE IT!

My code is indentical to yours.