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 my code not working

Why is my code not working? it ask me to

"Write a method inside the Frog class named EatFly. It should take a single integer parameter named distanceToFly and return a bool value. It should return true if the frog can reach the fly with its tongue, and false otherwise."

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

        public bool EatFly(bool distanceToFly)
        {
            bool canEat = distanceToFly <= tongueLength;
        }
    }
}

1 Answer

andren
andren
28,558 Points

There are three issues in your code:

  1. You define the distanceToFly parameter as a bool, which it is not. It is an int.

  2. The name of the tongue length variable is TongueLength not tongueLength, the latter version is just a parameter used in the class constructor.

  3. You are missing a return statement in your method.

If you fix those issues then your code will work.