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

Herman Vicens
Herman Vicens
12,540 Points

Don't understand the message

There is a problem with the conditional expression that I can't see. been stuck here for a while. I think I got the conditions exactly as stated in the instructions but apparently not.

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

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

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

2 Answers

andren
andren
28,558 Points

The method you add is supposed to take distanceToFly as it's first parameter, not tongueLength. And you are meant to compare the TongueLength (field) to the distanceToFly parameter that is passed in.

So you are not meant to add a DistanceToFly field as you have done, or to add code to the original EatFly method that comes with the challenge.

If you fix those issues like this:

namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;
        // Removed DistanceToFly field

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

        public bool EatFly(int distanceToFly)       
        {
            return TongueLength >= distanceToFly;
        }
        // Changed tongueLength to distanceToFly
        public bool EatFly(int distanceToFly, int flyReactionTime) 
        {
            // Changed tongueLength >= DistanceToFly to TongueLength >= distanceToFly
            return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;
        }
    }
}

Then the code will work.