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#

Don't understand why it wont work

I'm working on the code challenge in the methods video that wants to do the following:

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.

I do

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

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;

    }

    public bool EatFly(int distanceToFly)
    {

       if(TongueLength == distanceToFly){
        return true;
       } 


       return false;

    }

}

}

but when check this work it says it is wrong "The frog should be able to eat flies within the reach of its tongue."

I think my logic is correct if not please help.

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you need to change it from just checking if the distances are equal. there are other options like greater than or equal to. that would cover distances from the frog up to the length of its tongue.

ok I got it instead of using == i used length < distance ..... wouldnt the equal be correct as well tho ? ... if they are equal then return true else return false ... okay so im over thinking it.... when i put equal that if the length is greater than distance the method would return false but logically if the length is great than the distance the frog should still be able to eat. thanks for the help =)

Well then the TongueLength == distanceToFly would be false and it would not return true.. it would return false... i can add the else block after the if statement but the samethign happens it does not let me get past it when i click check ...

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

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;

    }

    public bool EatFly(int distanceToFly)
    {

       if(TongueLength == distanceToFly){
        return true;
       } 
       else
       {
           return false;
       }



    }

}

}