Slumbering Sample javascript


#1

What is wrong? It is always “That is not right”

//var enemies = hero.findEnemies();
var friends = hero.findFriends();
var yetis = hero.findByType(“yeti”, friends);
//hero.say("yeti "+ yetis.length);

function averageSize(yetis) {
var sum = 0;
for (var i = 0; i < yetis.length; i++)
{
var ya = yetis[i];
sum = sum + ya.size;
}
return sum / yetis.length;
}

var a = averageSize(yetis);
hero.say(a);

P.S. Maybe it important, Yeties automaticaly dying at the beginning.


#2

It looks like the problem is in the first four lines.
Try hero.findByType("yeti") instead.
And the yetis are not friends.


#3

Already tried.

var yetis = hero.findByType(“yeti”);
function averageSize(yetis) {
var sum = 0;
// Go through each yak and add its size to the sum.
for (var i = 0; i < yetis.length; i++)
{
var ya = yetis[i];
sum = sum + ya.size;
}
return sum / yetis.length;
}

var a = averageSize(yetis);
hero.say(a);

And var yetis = hero.findByType(“yeti”, hero.findEnemies(); too

If i put hero.say("yeti "+ yetis.length);, it would be “Nan” of yeties.

I don’t know what to do.


#4

Please refresh the page and try again, or improve your glasses. I believe the problem is that you are unable to see the Yetis. I implemented a fix, but fixing your glasses should help, too.


#5

Thank you. With new glasses it is ok.