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

Write a method inside the Frog class named EatFly. It should take a single integer parameter named distanceToFly and ret

can Anyone help me please

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

        public Frog(int tongueLength)
        {
           bool reach = distanceToFly >= tongueLength;
            return reach;
        }
    }
}

3 Answers

Steven Parker
Steven Parker
220,451 Points

Here's a few hints:

  • don't make any changes to the "Frog" constructor, add your new method after it.
  • your new methods name should be "EatFly"
  • your method should take a parameter named "distanceToFly"
  • your code to test the distance should use the "TongueLength" field (with capital "T")

Give it another try with these in mind and I'll bet you get it. If not, write again with your revised code.

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

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;
    }
    public  bool EatFly(int distanceFly)
      {
      bool reachSky = distanceFly >= TongueLength;


    }
}

}

I am trying , but it is not working !

Steven Parker
Steven Parker
220,451 Points

Close, but this time you forgot to return the result.

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

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

}
}

}

what about this time;

Steven Parker
Steven Parker
220,451 Points

The function should return a true value when the tongue is longer or equal to the distance.

Also, the challenge can be a bit picky about formatting. You might need to remove the extra space between "public" and "bool".