that fixed that part technicly but wait theres more
// You are trapped. Don't move, it'll be painful.
// This function checks if the enemy is in your attack range.
function inAttackRange(enemy) {
var distance = hero.distanceTo(enemy);
// Almost all swords have attack range of 3.
if (distance <= 3) {
return true;
} else {
return false;
}
}
// Attack ogres only when they're within reach.
while (true) {
// Find the nearest enemy and store it in a variable.
var enemy = hero.findNearestEnemy();
// Call inAttackRange(enemy), with the enemy as the argument
// and save the result in the variable canAttack.
var canAttack = inAttackRange(enemy);
if (canAttack = True) {
// If the result stored in canAttack is true, then attack!
hero.attack(enemy);
}
}
Congrats on solving it, but please remove the solution as posting solutions is prohibited on the discourse because it will ruin the purpose of learning, thanks
It only needed == not ===, CodeCombat just wanted === because it’s better practice :] (and wait, ANOTHER thing, if you just wrote if (canAttack) { it would’ve also been fine)
Also, just a side note, this is JavaScript and not Java, please be clear next time