Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Village champion JS

I need help on VIllage champion because I have no idea what I’m doing wrong and no idea what to do.

// Incoming munchkins! Defend the town!

// Define your own function to fight the enemy!
function cleaveOrAttack() {
    // In the function, find an enemy, then cleave or attack it.
    var ogre = hero.findNearestEnemy();
    if (ogre) {
        if (hero.isReady("cleave")) {
            hero.cleave(ogre);
        }
        // Else attack the ogre:
        else {
            hero.attack(orge);
        }
    }
}


// Move between patrol points and call the function.
while (true) {
    hero.moveXY(35, 34);
   function cleaveOrAttack() {
     hero.attack(orge ); 
           
   }
  
    hero.moveXY(47, 27);
    // Call the function again.
    function cleaveOrAttack() {
     hero.attack(orge );
    }
    hero.moveXY(60, 31);
    // Call the function again.
    function cleaveOrAttack() {
     hero.attack(orge ); 
}
 }

Try to remove the attack after each cleaveOrAttack and I think that should work fine

That didn’t do it either. I will posts a screenshot with the problem.

On line 22, remove the word **function **

I don’t know what’s going on but that doesn’t work either idk what to do.

What is your new code?

// Incoming munchkins! Defend the town!

// Define your own function to fight the enemy!
function cleaveOrAttack() {
    // In the function, find an enemy, then cleave or attack it.
    var ogre = hero.findNearestEnemy();
    if (ogre) {
        if (hero.isReady("cleave")) {
            hero.cleave(ogre);
        }
        // Else attack the ogre:
        else {
            hero.attack(ogre);
        }
    }
}


// Move between patrol points and call the function.
while (true) {
    hero.moveXY(35, 34);
    // Use cleaveOrAttack function you defined above.
     cleaveOrAttack() ;
    hero.moveXY(47, 27);
    // Call the function again.
     cleaveOrAttack(); 
    hero.moveXY(60, 31);
    // Call the function again.
     cleaveOrAttack(); 
 }



I am positive it is right

It is all right in my opinion. So it works?

not at all that’s the problem.

What part of your code doesn’t work?

the whole thing does not work

Can you show me your equipment?

don’t have any because I am on a student acc😐

The function is fine, maybe try to look closer at where you go.

Well, you should create an individual account (it is lots of more fun)

I think I will because having a student acc isn’t fun at all

I see the error. Remove the while True loop.

yep that was the problem. thank you :pray:t5: