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 PointsI'm confused
In this code in the for loop I need to get the average of the tongue lengths and I don't know how. Please Help
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
for(int i = 0; i < frogs.Length; i++)
{
frogs / frogs.Length;
}
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Daniel Tkach
7,608 PointsHi Michael, let me help, meaning, I assume you don't want the answer, right? First of all this line: frogs / frogs.Length; does not mean anything hanging in there, an operation not assigned to any variables. Do you understand this?
Then let's think first what we have to do, forget about the code: you have to calculate and average, right? this is the sum of each item, divided by the total number of items. What you can achieve with the for is add up each of the length values to a variable that you will declare, you can call it "totalLengths" or whatever.
If you understand this far then you got it.
Moderator Edit: Moved response from Comments Section to Answers.
Michael North
2,561 PointsMichael North
2,561 PointsI'm sorry I still don't understand how to add all the indexes up.