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 trialBenneth Paredis
4,597 PointsQuick Question
What am i doing wrong in this excercise , its supposed to return true if the tongueLength is less or equal to the distance of the fly.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
bool EatFly = int distanceToFly <= tongueLength;
}
}
}
Babatunde Obidare
Courses Plus Student 10,514 PointsWhat error message are you getting?
Do you have a Main Method? Are your variables assigned?
The int distanceToFly variable has not been declared/assigned properly
Here is the correct code below:
namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength; public int distanceToFly;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly( int distanceToFly)
{
bool ableToEat = TongueLength >= distanceToFly;
return ableToEat;
}
}
}
Benneth Paredis
4,597 PointsIt keeps saying "Did you create a parameter in your method named distanceToFly?" even after i wrote the code that you send me.
Edit: nevermind i got it now, thanks alot !
1 Answer
Babatunde Obidare
Full Stack JavaScript Techdegree Student 4,925 PointsI'm glad that I'm able to help.
Lewis Gilbert
2,082 PointsLewis Gilbert
2,082 PointsHi, at the moment you are not specifying a return type e.g. Bool, String, Int etc... for your method. In this case you are looking to return a bool.
"int distanceToFly" doesn't actually hold a value nor is it initialized.
Finally you need to use the "return" keyword to return a value to the method caller!
Below is a working solution that i have made for you :) Thanks