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 trialDarya Zata
2,562 PointsEatFly doesnt work
the method eatfly doesnt work eatherway
mastercode doesnt work ,
need help thanks
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly (int distanceToFLy)
{
bool eaten = TongueLength>=distanceToFLy;
return eaten;
}
}
}
1 Answer
Michael Fish
7,804 PointsHello Darya,
Looks like you created the EatFly method correctly. Inside of the EatFly method you need to check if the fly is close enough to the frog to be eaten.
Try this:
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
//Is the frog's tongue long enough to reach the fly?
if(distanceToFly <= TongueLength)
{
return true; // Fly is eaten
} else
{
return false; // Fly is not eaten
}
}
}
}
Darya Zata
2,562 PointsDarya Zata
2,562 PointsHello Michael,
thank you for the answer, hm but I had also the similar code (I would say the same one) but if I try to pass with my code it shows a mistake, if I copy yours its ok .. I dont understand why
here is my code:
public bool EatFly (int distanceToFLy) { if( TongueLength >= distanceToFLy ) { return true; } else { return false; } }
Michael Fish
7,804 PointsMichael Fish
7,804 PointsI see you are checking if TongueLength is greater than or equal to distanceToFly and I'm checking if distanceToFly is less than or equal to TongueLength. These both seem like correct answers. They should work but I think maybe they forgot to add both as possible correct answers.