Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Methods Methods

Matt Clarke
Matt Clarke
6,712 Points

Please could someone help me complete this task?

Not getting any compiler errors but still cant figure out how to get it working.

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

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

3 Answers

Steven Parker
Steven Parker
221,297 Points

:point_right: You just forgot to declare the type of argument that EatFly takes.

Other than that, good job! :+1:

Optionally, since you compute a boolean return value, you could just return it directly (and you can simplify the test a bit):

        public bool EatFly(int distanceToFly)
        {
            return distanceToFly <= TongueLength;
        }
Charles Williams
Charles Williams
2,680 Points

You forgot to specify type of distanceToFly (int). Also it helps to separate boolean logic with paren to make it easier to read:

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        public bool EatFly(int distanceToFly)
        {
            bool EatFly = (distanceToFly <= TongueLength) && (distanceToFly >= 0);
            return EatFly;
        }
    }
}
Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,485 Points

It says you didnt create a parameter to method distanceToFly. Im getting an error.