Hi All,
Hope someone can offer some guidance. I have run the code through a Javascript validator for errors in the syntax and everything clears. The attack enemy works but the pick up coins doesn’t.
Here is the code:
// Peons are trying to steal your coins!
// Write a function to squash them before they can take your coins.
function pickUpCoins() {
var coin = hero.findNearestItem();
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy() {
while (true) {
var enemy = hero.findNearestEnemy();
if (enemy) {
// If there is an enemy, attack it!
hero.attack(enemy);
}
}
}
while (true) {
attackEnemy();
}
while (true) {
pickUpCoins();
}
Any help is appreciated.