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 trialAndrada Terenche
1,103 PointsCode Challenge Task 3 Confusion
My code works, it's just that I didn't quite understand why we used TongueLength and ReactionTime while distanceToFly and flyReactionTime in lowercase. I still don't do well with constructers...
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime;
public Frog(int tongueLength, int reactionTime)
{
TongueLength = tongueLength;
ReactionTime = reactionTime;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
public bool EatFly(int distanceToFly, int flyReactionTime)
{
return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;
}
}
}
3 Answers
Jon Wood
9,884 PointsTongueLength
and ReactionTime
are fields on the class (eventually you'll learn about properties, which are even better). They can be accessed anywhere in the class. The distanceToFly
and flyReactionTime
are just parameters to their respective methods. They are only accessible in the method they are parameters to.
In terms of the constructor, this is what initially sets the TongueLength
and ReactionTime
fields so they have the correct values to use as you're calling methods on the class.
Hope that helps at least a little bit, but let me know if you need further help.
Fabian Pijpers
Courses Plus Student 41,372 PointsFirst off all that which you have used as a return statement must be used within an iff statement. so if(TongueLength >= distanceToFly && ReactionTime <= flyReactionTime) { return ?????; }
Fabian Pijpers
Courses Plus Student 41,372 PointsThe only Problem I have now is knowing what to return know. Do you have that answer?