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 trialalexis potvin
Front End Web Development Techdegree Student 927 PointsWhy 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."
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
28,558 PointsThere are three issues in your code:
You define the
distanceToFly
parameter as abool
, which it is not. It is anint
.The name of the tongue length variable is
TongueLength
nottongueLength
, the latter version is just a parameter used in the class constructor.You are missing a return statement in your method.
If you fix those issues then your code will work.