while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Find the distance to the enemy with distanceTo.
        var distance = hero.distanceTo(enemy);
        // If the distance is less than 5 meters...
        if(distance < 5) {
            
        

while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Find the distance to the enemy with distanceTo.
        var distance = hero.distanceTo(enemy);
        // If the distance is less than 5 meters...
        if (distance < 5) {
            

// You can put one if-statement within another if-statement.
// Be careful how the if statements interact with each other.
// It's helpful to start with one outer if/else,
// using comments as placeholders for the inner if/else:

while(true) {
    var enemy = hero.findNearestEnemy();
    // If there is an enemy, then...
    if(enemy) {
        // Create a distance variable with distanceTo.
        var distance = this.distanceTo(enemy);
        // If the distance is less than 5 meters, then attack.
        if(distance < 5){
                  this.attack(enemy);
        }

while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Find the distance to the enemy with distanceTo.
        var distance = hero.distanceTo(enemy);
        // If the distance is less than 5 meters...
        if(distance < 5){
                  

// This function attacks the nearest enemy.
function findAndAttackEnemy() {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
}

// Define a function to cleave enemies (but only when the ability is ready).
function findAndCleaveEnemy() {
    // Find the nearest enemy:
    var enemy = hero.findNearestEnemy();
    // If an enemy exists:
    if (enemy) {
        
    
        // And if "cleave" is ready:
        if (hero.isReady("cleave")) {
        
            // It's time to cleave!
       
        hero.cleave(enemy);
    }
    }
}

// Destroy the mines!
// Use `say` to call out the range to the mines.
// Use division to calculate the range.

var enemy = hero.findNearestEnemy();
var distanceToEnemy = hero.distanceTo(enemy);
// Say first Range: distanceToEnemy divided by 3
hero.say(distanceToEnemy / 3);
hero.say("Fire!");
// Say second range: distanceToEnemy divided by 1.5
hero.say(distanceToEnemy / 1.5);
hero.say("Fire!");

while(true) {
    // Check the distance to the nearest enemy.
    var nearestEnemy = hero.findNearestEnemy();
    var distance = hero.distanceTo(nearestEnemy);
    // If it comes closer than 10 meters, cleave it!
    if (distance<10) {
        hero.cleave(nearestEnemy);
    }