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

John Krueger
John Krueger
1,996 Points

Method says not created.

Created a method but its saying that there is no method. How i fix this?

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        bool EatFly(int distanceToFly)
        {
            bool flyEaten = tongueLength  <= distanceToFly;
            return flyEaten; 
        }

    }
}

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Here are the issues with your method.

  • forgot public keyword.
  • tongueLength is a typo
  • <= is the wrong comparison operator to use here, either switch the place the 2 variables being compared or use >= instead.

And actually you really don't need the extra local variable bool flyEaten there, you can write the method body simply in one line.

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

hope it helps.

John Krueger
John Krueger
1,996 Points

I re-did the code to match yours but then its saying that "int distanceToFly" is not valid in current context.