Level: Wild Horses Need help

Hey I am stuck on this level! It keeps saying property X is undefined any help?
here is my code:
while(true) {
// How do you find the nearest friendly unit?
// horse = ?
var horse = hero.findFriends();
if (horse) {

var x1 = horse.pos.x - 7;
var x2 = horse.pos.x + 7;
if (x1 >= 1) {
    // Move to the horse's y position but use x1 for the x position.
    hero.moveXY(x1, y);
} else if (x2 <= 79) {
    // Move to the horse's y position but use x2 for the x position.
    hero.moveXY(x2, y);
}
var distance = hero.distanceTo(horse);
if (distance <= 10) {
    hero.say("Whoa");
    // Move to the red x to return the horse to the farm.
    hero.moveXY(27, 54);
    // Move back out into the pasture to begin looking for the next horse.
    hero.moveXY(41, 29);
}

}
}
It keeps saying property X is undefined any help?

This is what it’s says when I run the level

The function findFriends only returns an array of friends. You must say this to return an OBJECT:

hero.findFriends()[0];

2 Likes