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

can't figure out whats wrong with my for loop?

I think everything here is right but it keeps saying I'm wrong can someone help me figure out what I'm doing wrong?

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

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

2 Answers

Toni Ojala
Toni Ojala
17,570 Points

There actually are a couple of errors as well.

First there shouldn't be a semicolon at the end of the for loop. I mean after the i++. Secondly Length is a property value for arrays so it needs to be written with a capital L. So frogs.Length is what you're looking for.

Also, not an error, but assigning frogs[i] to another variable is a bit unnecessary since you can use it in the for loop as is. frogs[i].TongueLength

Stuart Wright
Stuart Wright
41,120 Points

There's nothing wrong with your for loop, but you need to do more than just assign the current frog to a variable. You need to add up the tongue lengths of each frog (declare a variable called 'total' or similar, and add the tongue length on each iteration of loop). Then at the end, divide total by the length of the frogs array to get the average.