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 trialdsteelz
1,203 Pointsi don't understand the question
"Return true if the frog’s tongue is longer or equal to than the distance to the fly and its reaction time is faster or equal to than the fly’s reaction time."
I don't understand what the challenge is asking me to do. I only have one reactionTime variable. is the question asking me to compare two reactionTimes?
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)
{
if (TonugeLength >= distanceToFly &&
}
}
}
2 Answers
Mark Phillips
1,749 PointsYou've added a second parameter to the constructor that sets a variable on Frog instantiation.
The question is getting you to use the second variable to check 2 predicates.
- how far to the fly?
- will the fly react before the frog?
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;
}
// overload the EatFly method to take in the additional parameter
public bool EatFly(int distanceToFly, int flyReactionTime)
{
if(TongueLength >= distanceToFly && ReactionTime <= flyReactionTime)
{
return true;
}
else
{
return false;
}
}
}
}
andren
28,558 PointsThere are in fact two variables containing reaction times.
There is the class property called ReactionTime
which store's the frogs reaction time. And then there is flyReactionTime
which is passed in to the method as a parameter and contains the fly's reaction time.
And yes you are meant to compare them to check that the frog has a faster reaction time than the fly.
dsteelz
1,203 Pointsthanks for the clarification, the challenge makes so much sense now
dsteelz
1,203 Pointsdsteelz
1,203 Pointsthanks for the assist, i see now that i misread the question. your comments/code really helped me