Forest Fire Dancing Help (JavaScript)

Hi I have a problem with level Forest Fire Dancing.
Can you identify the problem with code?

while (true) {
var evilstone = hero.findNearestItem();
if (evilstone) {
var pos = evilstone.pos;
if (pos.x == 34) {
hero.moveXY(46, 22);
} else {
var evilstone = hero.findNearestItem();
}
if (evilstone) {
var pos = evilstone.pos;
if (pos.x == 46) {
hero.moveXY(34, 22);
}
} else {
var evilstone = hero.findNearestItem();
if (!evilstone) {
hero.move(40, 22);
}
}
}
}

P.S. Sorry if my engilsh is bad.

if (!evilstone) {
hero.move(40, 22); hero.moveXY(x,y)

That still doesn’t help…

I just tried it and it still doesn’t work.

You only have to find the evilstone and the pos once so you can remove all the other times you look for it to clean up the code. When you get to the first else, just look at the second position.

if (pos.x == 46) {
hero.moveXY(34, 22);
}

The second else only needs to move the hero to the middle position.

To help with any formatting problems, you’ll need to format the code correctly when posting it.