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

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: