while(true) {
var farthest = null;
var maxDistance = 0;
var enemyIndex = 0;
var enemies = hero.findEnemies();
// Look at all the enemies to figure out which one is farthest away.
while (enemyIndex < enemies.length) {
var target = enemies[enemyIndex];
enemyIndex += 1;
// Is this enemy farther than the farthest we've seen so far?
var distance = hero.distanceTo(target);
if (distance > maxDistance) {
maxDistance = distance;
farthest = target;
}
}
if (farthest) {
// Take out the farthest enemy!
// Keep attacking the enemy while its health is greater than 0.
while(health > 0) {
var enemy = hero.findFarthestEnemy();
hero.attack(enemy);
}
Hey @Saadval! Welcome to Codecombat discourse! We have a lot of fun around here coding and talking about different topics. Before you continue, please check out our rules and guidelines so that you can become more familiar with how things go around here :).
Now with that being said could you please format your code properly.
You would do that by putting two of these:
`
At the beginning and end of your code so this:
while(true) {
var farthest = null;
var maxDistance = 0;
var enemyIndex = 0;
var enemies = hero.findEnemies();
Would look like this: while(true) { var farthest = null; var maxDistance = 0; var enemyIndex = 0; var enemies = hero.findEnemies();
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!