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 Methods

nave lahav
nave lahav
388 Points

why is this wrong

it says: Did you create a method named EatFly that returns a bool value? which I did.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
              bool EatFly(int distanceToFly);
            {
                bool reach = distanceToFly<tongueLength;
                return reach;
            }

        }
    }
}

1 Answer

Christian Mangeng
Christian Mangeng
15,970 Points

Hi nave,

1) Right now your EatFly method is inside the constructor method ( public Frog() ). Move EatFly outside of the constructor, as EatFly is a new method.

2) Now that EatFly is outside the constructor, you will have to use TongueLength instead of tongueLength (tongueLength is only accessible inside the constructor)

3) you can let the EatFly method directly return the comparison, it will return true or false this way:

return distanceToFly < TongueLength
nave lahav
nave lahav
388 Points

thank you very much!

I had a similar sort of problem with this and ended up with everything correct except the last line. I had:

 return EatFly(distanceToFly) <= TongueLength

I'm still not sure why it was wrong. Obviously I shouldn't have tried to return the method itself; but the '=' operator was not allowed?