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 trial

C# C# Objects Loops and Final Touches For Loops

Kiem Ruach
Kiem Ruach
2,267 Points

C# challenge

Am i getting closer?

FrogStats.cs
namespace Treehouse.CodeChallenges
{
    class FrogStats
    {
        public static double GetAverageTongueLength(Frog[] frogs)
        {
        for(i = 0; i < frogs.length; i++;)
            {
            return 
            }
        }
    }
}
Frog.cs
namespace Treehouse.CodeChallenges
{
    public class Frog
    {
        public int TongueLength { get; }

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,275 Points

Closer 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
Kiem Ruach
2,267 Points

I get what an average is, but Im not sure how to express it in code. Would you give me the first step?

Steven Parker
Steven Parker
231,275 Points

Typically, you build up a sum in the loop, then after it ends, divide the sum by number (Length) of items.