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

I need help on this i am stuck

i need help with If-stravaganza level an here is my code:
– Defeat the ogres from within their own camp!

while true do
local enemy = hero:findNearestEnemy();
– Use an if-statement to check if an enemy exists:
if enemy then
hero:attack(enemy)
hero:attack(enemy)
end
end

while true do
local enemy = hero:findNearestEnemy()
if enemy then
hero:attack(enemy)
end
end

@ducky
– Defeat the ogres from within their own camp!

while true do
local enemy = hero:findNearestEnemy();
– Use an if-statement to check if an enemy exists:

    -- Attack the enemy if it exists:

end

How are you stuck? Could you please format your code properly? Read this:

@ducky

// Use your new "cleave" skill as often as you can.

hero.moveXY(23, 23);
while(true) {
    var enemy = hero.findNearestEnemy();
    if (hero.isReady("cleave")) {
        // Cleave the enemy!
        
    }
    else {
        // Else (if cleave isn't ready), do your normal attack.
        
    }
}
here

Thank you.
I don’t code JavaScript, but can still process the basics.
What do you need help on? Could you please explain and elaborate on what you’re stuck on?

i dont understand how the cleave works at all.

It’s hero.cleave(enemy); I think

here is the code help for cleave

if (hero.isReady("cleave")) {
    hero.cleave(enemy);
} else {
    hero.attack(enemy);
}

I think that should work.

what about this
image

@ducky
what about this
image

@mr_javascript @ducky
here is my code can you help me

// Use your new "cleave" skill as often as you can.

hero.moveXY(23, 23);
while(true) {
    var enemy = hero.findNearestEnemy();
    if (hero.isReady("cleave")) {
        // Cleave the enemy!
        hero.electrocute(hero.findNearestEnemy());
    }
    else {
        // Else (if cleave isn't ready), do your normal attack.
        
    }
}

Why are you electrocuting anybody?
Aren’t you supposed to cleave?

@ducky
because what if hero.cleave isn’t ready

Remember you said this? This was right.

@ducky
you are correct and join my clan by going to this url TBRNfrags