Like the title says, when I run my code, my hero is killed by an ogre, though the rest runs smoothly. I was hoping someone might be able to give me a hint as to what’s going wrong. Here is my code:
// Your pet should translate commands.
function onHear(event) {
// The message the pet heard is in event.message
var message = event.message;
// If the message is "North":
if (message == "North") {
// The pet says "Htron".
pet.say("Htron");
}
// If the message is "South":
if (message == "South") {
// The pet says "Htuos".
pet.say("Htuos");
}
// If the message is "East":
if (message == "East") {
// The pet says "Tsae".
pet.say("Tsae");
}
}
// Assign the event handler.
pet.on("hear", onHear);
while (true) {
var enemy = hero.findNearestEnemy();
// Don't attack Brawlers.
if (enemy && enemy.type != "brawler") {
hero.attack(enemy);
}
}
Any hints would be greatly appreciated!