Passing through HELP please!

Hi guys,:blush:
can’t complete Passing Through level.

it says: Cant read property ‘pos’ of null
here is my code:

while(true) {
    var item = hero.findNearestItem();
    if(item) {
        // If item.type IS NOT EQUAL TO "gem"
        if(item.type != "gem") {
            // Then follow your pet wolf.
            hero.moveXY(pet.pos.x, pet.pos.y);
        }
        // Else:
    } else {
            // Move to the gem's position.
           hero.moveXY(item.pos.x, item.pos.y);
        
    }
}

thx!

sorry, first time here.

while(true) {
    var item = hero.findNearestItem();
    if(item) {
        // If item.type IS NOT EQUAL TO "gem"
        if(item.type != "gem") {
            // Then follow your pet wolf.
            hero.moveXY(pet.pos.x, pet.pos.y);
        }
        // Else:
    } else {
            // Move to the gem's position.
           hero.moveXY(item.pos.x, item.pos.y);
        
    }
}

while(true) {
    var item = hero.findNearestItem();
    if(item) {
        // If item.type IS NOT EQUAL TO "gem"
        if(item.type != "gem") {
            // Then follow your pet wolf.
            hero.moveXY(pet.pos.x, pet.pos.y);
        }
        // Else:
     else {
            // Move to the gem's position.
           hero.moveXY(item.pos.x, item.pos.y);
        }
    }
}
1 Like

oh, wrong placed { }
Thanks, man, really appreciate your help!

that code does not work

// N’insulte pas cette tribu d’ogres pacifiques.
while (true) {
var item = hero.findNearestItem();
if (item) {
// If item.type N’EST PAS EGAL A “gem”
if (item.type != “gem”) {
// Ensuite, suit ton loup domestique.
hero.moveXY(pet.pos.x, pet.pos.y);
}else{
hero.moveXY(item.pos.x, item.pos.y);
hero.moveXY(item.pos.x, pet.pos.y);
}
//
// Déplace-toi jusqu’à la position de la gemme
}
}

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Hi @Chaunk_Doe, welcome to the forum.
Do you have a problem with your code? It seems to work for me.
If not, please could you edit your post to remove the solution, so that other people can’t see it. I appreciate you trying to help these people by giving them the answer, but we prefer to give people hints so that they can learn while solving the level.
Thanks!
Danny