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

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
231,248 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
231,248 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
231,248 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".