I don’t know why it’s not working
Can you help me please??
// Shout to activate the bombs and move to the entrance.
// The function checks if numbers are almost equal.
function almostEqual(n1, n2) {
return Math.abs(n1 - n2) <= 0.5;
}
// The function checks that all
// thangs are on the same distance from the hero.
function allSameDistance(thangs) {
if (thangs.length === 0) {
return true;
}
// We can use any thang as an etalon.
var etalon = hero.distanceTo(thangs[0]);
// Iterate all thangs:
for(var x = 0 ; x <= thangs.length ; x++){
var thang = thangs[x];
// Use almostEqual to check if not the distance
// between the unit and the etalon:
var distance = hero.distanceTo(thang);
if (!(almostEqual(distance, etalon))){
// Return false.
return false;
}
}
// All the same. Return true.
return true;
}
var bombs = hero.findEnemies();
for (var x = 36; x <= 44; x++) {
for (var y = 30; y <= 38; y++) {
hero.moveXY(x, y);
if (allSameDistance(bombs)) {
// It's a safe spot. Rock'n'Roll!
hero.say("HEEEEEEEEEY!!!");
hero.moveXY(40, 56);
}
}
}
hero.say("Heh. Nothing.");
```