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

How to phrase this distanceToFly method

Unsure what the compiler is looking for as far as returning a value. Thanks for any assistance.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

        public bool EatFly(int distanceToFly)
        {  

           return  canReach;
        }
    }
}
Robert Angi-Lazar
Robert Angi-Lazar
3,738 Points

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

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;
    }

    public bool EatFly(int distanceToFly)
    {  

      bool canReach = TongueLength > distanceToFly;

     return canReach;

    }
}

}

1 Answer

andren
andren
28,558 Points

It should return a Boolean. In other words true or false. It's worth noting that comparisons like 5 > 2 or 8 != 2 actually return Boolean values that reflect the result of the comparison. So you can return a Boolean by returning the result of a comparison.

So you should write some comparison that will be true if the frog's tongue can reach the fly and false otherwise. And then return that comparison.