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

why is this code not correct? I've done everything the way it should haven't I?

my task is to make a method which takes a parameter called distanceToFly and checks if the frog can reach it

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        public bool Eatfly(distanceToFly){
        bool eatfly=distanceToFly<=Frog.TongueLenght;
            return(eatfly);
        }
    } 
}

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

There are 4 edits here which will make your code pass the challenge:

  • The challenge wants the method to be called EatFly, not Eatfly (notice the uppercase F).
  • You have a typo inside your method - 'TongueLenght' should be TongueLength.
  • You don't need to write Frog.TongueLength inside the method, you can access it using simply TongueLength.
  • Your parameter, distanceToFly, needs to have its type declared in the function header (int).

Hope that helps. Let me know if you need any of them explained further.

got it, thank you!