Need help on level Back to back on the forest

Help,On the level “Back to back” In the forest,the line that says “# Either attack the enemy…” Has a error malfunction that doesnt allow me to continue running the codes…

It says “a.csredux.parse is not a function”.Please help me it would we great

Screenshot it if you can and paste your code here as well.

# Either attack the enemy...
        rightEnemy = self.findNearestEnemy()
        self.attack(rightEnemy)
        self.attack(rightEnemy)

Try this for your attack

If you are writing your code in python otherwise disregard that

@MrPolarPotato I tried to recreate the error you got and couldn’t figure out how you got it, but here is the correct way to right the code in JavaScript with explanation

JavaScript Correct Answer:

// Stay in the middle and defend!

while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        //Either attack the enemy...
        hero.attack(enemy);
    }
    else {
        // ... or move back to your defensive position.
        hero.moveXY(40, 34);
    }
}

What you had to do was first set a variable inside the while loop so that you could find the nearest enemy like so.

while(true) {
    var enemy = hero.findNearestEnemy();

Then you had make an if statement that would tell your character to attack the nearest enemy like so:
The code is basically saying if there is enemy near that means true so your hero will attack.

    if (enemy) {
        //Either attack the enemy...
        hero.attack(enemy);
    }

Finally you had to make the character move back to the starter position by creating an else statement.

    else {
        // ... or move back to your defensive position.
        hero.moveXY(40, 34);
    }

@Aleigh5 now I am not sure on python programming but if while loops work the same was as JavaScript you wouldn’t need that second self.attack(rightEnemy) since the while loop will continue to run self.attack(rightEnemy) until there wasn’t an enemy any longer. You’re code is correct by logic can just shorten it up :P.