C# C# Objects Methods Methods

Please help with this task question.

Write a method inside the Frog class named EatFly. It should take a single integer parameter named distanceToFly and return a bool value. It should return true if the frog can reach the fly with its tongue, and false otherwise.

Thats the code and I feel I have it right but its not accepting it. Any help?

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

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

        public Eatfly(int distanceToFly)
        {
            bool distance = tongueLength <= distance to fly;
            return distance;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
182,288 Points

You're close, but there are a few issues:

  • you need to specify the return type (bool) of the method
  • the method name must be "EatFly", with a capital "F"
  • the tongue length needs to be greater than or equal to the distance for the frog to reach the fly
  • the parameter name must be written as "distanceToFly" (with exact capitalization and no spaces)

Thank you, Steven! It was for sure the first point that was messing me up! The other three I had realized, but I had totally forgot about the return type! Thanks!

Steven Parker
Steven Parker
182,288 Points

Dale Thornton — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!