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

Sadettin Senberber
Sadettin Senberber
974 Points

I don't understand what went wrong?

If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly. This is the warning. I think I'm use true mark that question wants. Please help.

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

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

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly; 

        }
        public readonly int ReactionTime;


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


            return ReactionTime <= flyReactionTime;

        }

    }
}

1 Answer

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

Hi there! I feel like you're doing pretty well, but you're missing an important aspect here. A method can only ever return one time. Your method has two return statements. Once a return has been hit, the method will cease execution. You need to combine those two and return the boolean of if the frog's tongue is greater than the distance AND the frog's reaction time is less than the fly's.

Give it another go with this hint in mind, but let me know if you're still stuck! :sparkles:

Sadettin Senberber
Sadettin Senberber
974 Points

Thank you very much it works.