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 trialAmar Resic
2,922 PointsCoding challenge confusion. Return the average length of the tongues of the frogs in the array.
Really confused on what exactly this exercise wants me to do. It seems much different from the video example. Is it looking for me to calculate the the average tongue length on my own or return that array in the other frog.cs file? Also confusion with the array being a double and everything else being an int. I feel like I'm really over thinking this and cannot figure out what this actually wants me to do.
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
int frogToungeLength = 0;
int frogTotal = 0;
for(int i=0; i < frogs.Length; i++)
{
frogToungeLength = frogToungeLength + frogs[i];
frogTotal++;
}
return frogToungeLength/frogTotal;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 PointsYou need to reference the TongueLength
property in the Frog object.
frogs[i].TongueLength
Otherwise your code works.