Help with Cursed Wonderglade [javascript]

I did the code but it keeps giving me an error and I can’t find what is wrong with my code? Please help me identify the mistake

while (true) {
// Find the nearest item.
// Collect it (if it exists) only if its type isn’t “gem”.
var item = hero.findNearest(hero.findItems());
if (item & item.type!=“gem”){
this.moveXY(item.pos.x, item.pos.y);
}
// Find the nearest enemy.
// Attack it if it exists and its type isn’t “burl”.
var nearest = hero.findNearest(hero.findEnemies());
if (nearest & nearest.type!=“burl”){
hero.cast(“drain-life”, nearest);
}

}

&&

[Post must be at least 20 characters]

thank you so much! it worked. I switched from python to java and still learning

1 Like

mine is python but i still need help i dont know whats wrong

You need to check the existence of an item and enemies.

1 Like

pls help i have been stuck a long time

while True:
    # Find the nearest item.
    # Collect it (if it exists) only if its type isn’t “gem”.
    enemy = hero.findNearestItem()
if enemy and enemy.type != "burl":
    hero.attack(enemy)
else:
    pass
item = hero.findNearestItem()
if item and item.type != "gem":
    hero.moveXY(item.pos.x, item.pos.y)
# Find the nearest enemy.
# Attack it if it exists and its type isn’t “burl”.
if enemy:
    hero.attack(enemy)
else:
    hero.findNearestItem()

Never happens because all that’s in the while True looop is finding the nearest enemy.

1 Like

thanks! youre awesome😀