Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,149 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.