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 Methods Method Overloading

Shing wai Chan
Shing wai Chan
1,255 Points

I try to overload the methode, but i can't get it working.

The question is to overload the methode, but it seems to be stuck or i have some wrong code somewhere i can't quite see it.

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

        public Frog(int tongueLength, int reactionTime)
        {
            TongueLength = tongueLength;
            ReactionTime = reactionTime;
        }

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }
        public bool EatFly(int distanceToFly , int flyReactionTime)
        {
          return  TongueLength >= distanceToFly && ReactionTime >= flyReactionTime;
        }

    }
}

3 Answers

Steven Parker
Steven Parker
231,269 Points

Apparently the challenge does not like a space between the first argument and the comma, even though it is perfectly legitimate code. You might report this as a bug to Treehouse Support, it may get you "a special Exterminator badge".

You also compared your reaction time using the "greater than or equals" (>=) operator. But a faster reaction time would be less than.

I'll bet you can fix it with these hints and without an explicit spoiler.

anil rahman
anil rahman
7,786 Points
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

        public Frog(int tongueLength, int reactionTime)
        {
            TongueLength = tongueLength;
            ReactionTime = reactionTime;
        }

        public bool EatFly(int distanceToFly, int flyReactionTime)
        {
            return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;
        }

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }
    }
}
Jeremy McLain
STAFF
Jeremy McLain
Treehouse Guest Teacher

There was a problem with the code challenge not accepting spaces. This has been fixed now.