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 trialAJ Allen
1,390 PointsShouldn't it return true if ReactionTime >= flyReactionTime? It's returning true for ReactionTime <= flyReactionTime
Am I missing something? Why would the frog's reaction time being <= the fly's make it faster? Wouldn't that mean the frog has a lesser reaction time?
Thank you,
- AJ
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;
}
}
2 Answers
Steven Parker
231,248 PointsIt looks like you're missing the closing brace at the end of the new EatFly method, causing a syntax error.
Once you fix that, the challenge checker will evaluate your code and return "Bummer! If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly."
So yes, to pass the challenge, your code must test that the frog reaction time is less than or equal to the fly's.
Brody Ricketts
15,612 Points@AJ Allen
Consider this.
The last candy bar is on the table between you are your friend. You know their reaction time is .56 seconds (Just over 1/2 seconds). You want to beat them to the candy bar. How fast must your reaction time be to get to the candy bar before your buddy?
Checking your code as it is written in this forum post you get:
"Bummer! If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly."
"Reaction time is the amount of time it takes to respond to a stimulus."
Think of reaction time as a delay. If your delay is greater than your friends (myReactionTime > friendsReactionTime), you took more time to get to the candy bar.
Daniel Dugan
16,904 PointsDaniel Dugan
16,904 PointsThank you for letting me think through it, instead of just pasting code!