Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael North
2,561 Pointsplease help
Can someone please go over my work and tell me what I did wrong? thank you
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
int totalLengths = 0;
for(int i = 0; i < frogs.Length; i++)
{
totalLengths = Frog.TongueLength + totalLengths;
}
int average = totalLengths / frogs.Length;
return average;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Steven Parker
231,198 PointsYou'll want to access the TongueLength property of each instance.
So instead of "Frog.TongueLength
", you might write "frogs[i].TongueLength
" to get the specific length from the current instance.
Also, your function returns a double, so you might want to declare average that way instead of int.