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

What is the correct answer?

Everything I try isn't correct.

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

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

1 Answer

Chris Adamson
Chris Adamson
132,143 Points

You aren't far off, length should be Length, Frog.TongueLength is an Integer, and the temporary tongue double variable isn't needed.

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

Thanks! I didn't know that tongue was an int. in the in the method I saw that it was returning a double so I assumed that the tongue length may be a double.