Cursed Valley: Hard To Beat! Help Please!

So I’m stuck on Cursed Valley, and for some reason my hero isn’t moving to any potions so when it gets to that line nothing else happens! What’s wrong with my code?!

while (true) {

var enemy = hero.findNearestEnemy();
// Attack if enemy exists AND enemy.team is "ogres"
// AND enemy.type is "skeleton"
if (enemy && enemy.team === "ogres" && enemy.type === "skeleton") {
    hero.attack(enemy);
}


// Collect if item exists AND item.type is "potion"
// AND hero.health is less than hero.maxHealth / 4
if (item && item.type === "potion" && hero.maxHealth < hero.maxHealth / 4) {
    var item = hero.findNearestItem(); 
    hero.moveXY(item.pos.x, item.pos.y);

}

}

Looks like you’ve lost this line:

var item = hero.findNearestItem();

I tried adding that but my character stays in place!

new code:

// The hot sun is draining the hero’s health!

while (true) {

var enemy = hero.findNearestEnemy();
// Attack if enemy exists AND enemy.team is "ogres"
// AND enemy.type is "skeleton"
if (enemy && enemy.team === "ogres" && enemy.type === "skeleton") {
    hero.attack(enemy);
}
var item = hero.findNearestItem();

// Collect if item exists AND item.type is "potion"
// AND hero.health is less than hero.maxHealth / 4
if (item && item.type === "potion" && hero.maxHealth < hero.maxHealth / 4) {
    var item = hero.findNearestItem(); 
    hero.moveXY(item.pos.x, item.pos.y);

}

}

Could you say you username in CodeCombat? I’ll try to reseach the problem.

I’m not sure if it’s wrong but there is a problem with your enemies. so you have if ogres and skeletons, try to change it (instead of and put or)

My Username is “The99thRaider”

I tried using “or” instead of “and” but it didn’t work

Oh, I see the error now :slight_smile: Your hero attack enemies, but you have a problem with items

if (item && item.type === "potion" && hero.maxHealth < hero.maxHealth / 4) {

Look at this part: hero.maxHealth < hero.maxHealth / 4 . This expression can be true only for negative numbers :wink:

Ok, thanks! :relaxed: