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 trialJohn Krueger
1,996 PointsMethod says not created.
Created a method but its saying that there is no method. How i fix this?
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
bool EatFly(int distanceToFly)
{
bool flyEaten = tongueLength <= distanceToFly;
return flyEaten;
}
}
}
1 Answer
William Li
Courses Plus Student 26,868 PointsHere are the issues with your method.
- forgot
public
keyword. -
tongueLength
is a typo -
<=
is the wrong comparison operator to use here, either switch the place the 2 variables being compared or use>=
instead.
And actually you really don't need the extra local variable bool flyEaten
there, you can write the method body simply in one line.
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
hope it helps.
John Krueger
1,996 PointsJohn Krueger
1,996 PointsI re-did the code to match yours but then its saying that "int distanceToFly" is not valid in current context.