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

Uladzimir Barysenka
Uladzimir Barysenka
3,265 Points

I can't do this task

Where is a mistake?

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

FrogStats.cs
namespace Treehouse.CodeChallenges
{
    class FrogStats
    {
        public static double GetAverageTongueLength(Frog[] frogs)
        {
            int totalLength = 0;
            for (int i=frogs.Length-1; i>=0; i--)
            {
                totalLength =+ frogs[i].TongueLength;
            };
            return totalLength/frogs.Length;
        }
    }
}
Frog.cs
namespace Treehouse.CodeChallenges
{
    public class Frog
    {
        public int TongueLength { get; }

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

1 Answer

andren
andren
28,558 Points

You just have a typo in this line:

totalLength =+ frogs[i].TongueLength;

The =+ should be +=. If you fix that issue then your code will work.