Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Methods Methods

I am not sure why the challenge says my code is wrong.

I am unsure why the challenge is saying I failed.

The challenge wants me to return true if the fly is in reach of the mouth. the distanceToFly - TongueLength should equal 0 to make the statement true.

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

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

        public bool EatFly(int distanceToFly)
        {
            if(distanceToFly - TongueLength == 0)
            {
               return true; 
            }

            else
            {
                return false;   
            }

        }
    }
}

2 Answers

The mysterious down vote. It would help me (and maybe others) understand when this is done if there was an explanation as to why.

If you are 2 feet away and my arm is 2 feet long I can reach you.

If you are 2 feet away and my arm is 3 feet long I can still reach you.

Hint: Wouldn't the fly also be eaten if TongueLength was greater than distanceToFly? You are only considering if they are the same length.