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

Haldon Francis
Haldon Francis
619 Points

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

would like to know how to construct the boolean method to return the EatFly Method.

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

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

        bool EatFly(int distanceFly)
        {
           bool EatFly = distanceFly == tongueLength;
           return = Eatfly;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
229,732 Points

You have the right idea, but a few code issues:

  • the function needs a "public" access modifier
  • the field name is "TongueLength" (capital "T") instead of "tongueLength"
  • the test should be if the tongue is greater or equal instead of just equal
  • the variable name should be consistent, including the case of each letter ("F" vs "f")
  • there should be no "=" in a "return" statement
  • you could optionally return the value directly and skip creating a variable