[SOLVED] Expected an identifier and instead saw '.'.?

On Codecombat level Backwoods Forest - Leave it to the Cleaver I put in my code but it shows a red warning sign and a message saying “Expected an identifier and instead saw ‘.’.” Please send any suggestions or help on this, as it has happened many times before, but I still went through the level.
Also, I think I have the right code for this level, but it does not work for me. Here is my code:

// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called target
function cleaveWhenClose(target) {
    if(hero.distanceTo(target) < 5) {
        // Put your attack code here
        // If cleave is ready, then cleave target
       if hero.isReady("cleave");
           hero.cleave(target);
        // else, just attack target!
        else {
            hero.attack(target);
        }
    }
}

// This code is not part of the function.
while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Note that inside cleaveWhenClose, we refer to the enemy as target.
        cleaveWhenClose(enemy);
    }
}

Please send any help or suggestions on this too, as I cannot figure this out.

Please format according to the FAQ please

2 Likes
// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called target
function cleaveWhenClose(target) {
    if(hero.distanceTo(target) < 5) {
        // Put your attack code here
        // If cleave is ready, then cleave target
       if hero.isReady("cleave");
           hero.cleave(target);
        // else, just attack target!
        else {
            hero.attack(target);
        }
    }
}

// This code is not part of the function.
while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Note that inside cleaveWhenClose, we refer to the enemy as target.
        cleaveWhenClose(enemy);
    }
}
1 Like

here sorry I forgot to format it

1 Like

Please send a screenshot and give more info about what is wrong

I see what’s wrong. Your if (hero.isReady("cleave")); shouldn’t end in a semi-colon,because it is not a method. Rather, it should end with an identifier: that is to say, a curly bracket or { }. { is to open the if statement and } is to close it. You are missing both.

2 Likes

ty :DDD this worked!