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
182,566 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
182,566 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
182,566 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".