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

c#

What did I do wrong in this code?

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        public bool EatFly()
        {
        bool distanceToFly = tongueLength => distanceToFly;
            return: true;
        }
    }
}

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

According to the challenge description EatFly method takes 1 parameter, your version of code takes 0 parameter, so that's a mistake there. Additionally, we should make use of an if..else clause to check the difference between distanceToFly & TongueLength to determine whether the method should return true or false.

Frog.cs
        public bool EatFly(int distanceToFly) // method takes 1 parameter
        {
            if (distanceToFly - TongueLength <= 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

Ok thanks!