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.
var enemy= hero.findNearestEnemy();
while (enemy.health>0) {
hero.attack(enemy);
}
}
}
I donāt understand what I am doing wrong
My hero just keeps on attacking the decoys and not the ogres
Hi @Falcons118, welcome to the forum.
You seem to be missing some code at the top. Please could you post all of it. And if you put ```javascript at the start of your code it recognises the javascript comments, meaning the whole code isnāt red.
Thanks
Sorry about that⦠This is my first time posting something on this website
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;
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.
var enemy= hero.findNearestEnemy();
while (enemy.health>0) {
hero.attack(enemy);
}
}
}
@Deadpool198 is that better
@Deadpool198 can you help me now.
Inside the if farthest, what variable have you used to attack?
@Deadpool198 Isnāt the while loop supposed to be in there
You went through all the bother of determining āfarthestā, but now you arenāt going to use it?
@dedreous I donāt know how to use it. And when I click on the hints(in CodeCombat )thereās nothing useful that will help me in that level
Ok, letās fix that thenā¦I hope Danny wonāt mind my stepping in here 
Give me a few to take a closer look and Iāll repost my suggestions.
In your āif (farthest)ā code block, you are now re-defining āenemyā. You donāt need to do this, as āfarthestā is already defined as the enemy you want to take out first.
Attack farthest, not enemy.
Additionally, the Hints are an excellent resource, but not always revealing. It is always a good idea to have a look at them, but then do not be afraid to ask for help if they were not enough.
It is a very narrow line between giving away too little and giving away to much. The goal here is to help folks learn, after all 
@dedreous Thanks for the help
never mind it doesnāt work
My hero just says ābut its deadā
Can you tell me what I need to change now @dedreous
Repost your code, as it is nowā¦Iāll try to see if I can spot it.
while(true) {
var farthest = null;
var maxDistance = 0;
var enemyIndex = 0;
var enemies = hero.findEnemies();
var enemy = hero.findNearestEnemy();
while (enemyIndex < enemies.length) {
var target = enemies[enemyIndex];
enemyIndex += 1;
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(enemy.health>0) {
hero.attack(farthest);
}
}
}
I changed the attack enemy to attack farthest
@dedreous isnāt that what you told me to change