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

yujia liu
yujia liu
14,964 Points

what's wrong with my answer?

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);
    }    
}

}

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);
        }    
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great :smiley: There are two things going on here. One is a logic thing, and one is a "challenge is being picky" thing.

Here's the logic part: The reaction time of the frog should be less than the reaction time of the fly. Let's put it this way. If the frog reacts in 1 second, but the fly reacts in 5 seconds... well that's a free dinner for the frog!

Secondly, (and I have no idea why) even when you fix that part, the challenge will not pass without a space between the parameters in the function. Take a look:

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

Hope this helps! :dizzy: