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 trialKiem Ruach
2,267 PointsC# challenge
Am i getting closer?
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
for(i = 0; i < frogs.length; i++;)
{
return
}
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Steven Parker
231,268 PointsCloser than what? But some issues here are:
- the loop has a stray extra semicolon after the increment clause
- the return statement is missing a semicolon
- the return should be placed after of the loop instead of inside it
- the return should pass back a double value
- the code to compute the average still needs to be added (both inside and around the loop)
Kiem Ruach
2,267 PointsKiem Ruach
2,267 PointsI get what an average is, but Im not sure how to express it in code. Would you give me the first step?
Steven Parker
231,268 PointsSteven Parker
231,268 PointsTypically, you build up a sum in the loop, then after it ends, divide the sum by number (Length) of items.