Cursed Wonderglade Javascript Bug?

Every time I run my script I have “run out of time.” I can’t seem to find the issue. Any suggestions would be helpful. Thank you!

// Wonderglade has changed since our last visit.
// Ogres cursed it and we should defeat them.
// The burl still is collecting gems, so don't touch them.
// Also don't attack the burl.

while (true) {
    // Find the nearest item.
    // Collect it (if it exists) only if its type isn't "gem".
    var item = hero.findNearestItem();
    if (item && item.type != "gem") {
        hero.moveXY(item.pos.x, item.pos.y);
    }     
    // Find the nearest enemy.
    var enemy = hero.findNearestEnemy();
    // Attack it if it exists and its type isn't "burl".
    if (enemy && enemy.type != "burl") {
        hero.attack(enemy);
    } 
}

I have also tried:

// Wonderglade has changed since our last visit.
// Ogres cursed it and we should defeat them.
// The burl still is collecting gems, so don't touch them.
// Also don't attack the burl.

while (true) {
    // Find the nearest item.
    // Collect it (if it exists) only if its type isn't "gem".
    var item = hero.findNearestItem();
    if (item && item.type != "gem") {
        hero.moveXY(item.pos.x, item.pos.y);
    }     
}

while (true) {
    // Find the nearest enemy.
    var enemy = hero.findNearestEnemy();
    // Attack it if it exists and its type isn't "burl".
    if (enemy && enemy.type != "burl") {
        hero.attack(enemy);
    } 
}

Hello, Do you think that they can let people play games on here?

You have to use two seperate if statements for this level.

if (enemy) {
    if (enemy.type != "burl"){
        hero.attack(enemy);
}
}

The same thing applies for the items.

I tried it with the updated code, and I am still having the same issue.

// Wonderglade has changed since our last visit.
// Ogres cursed it and we should defeat them.
// The burl still is collecting gems, so don't touch them.
// Also don't attack the burl.

while (true) {
    // Find the nearest item.
    // Collect it (if it exists) only if its type isn't "gem".
    var item = hero.findNearestItem();
    if (item) {
        if(item.type != "gem") {
            hero.moveXY(item.pos.x, item.pos.y);
        }
    }     
    // Find the nearest enemy.
    var enemy = hero.findNearestEnemy();
    // Attack it if it exists and its type isn't "burl".
    if (enemy) {
        if(enemy.type != "burl") {
           hero.attack(enemy);
        }
    } 
}

I changed the character type that I was using, and it solved the problem.

2 Likes