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 trialNic Harrington
825 PointsKeep Getting Error About Reaction Time
I need some help, I have confidence that the code is okay- but I keep receving the error "If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly."
Am I missing something?
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(TongueLength >= distanceToFly && ReactionTime <= flyReactionTime);
{
return true;
}
}
}
}
1 Answer
Steven Parker
231,275 PointsThere's a stray semicolon after the "if" statement that prevents it from working, and the function still needs to return a value when the condition is not true.
Nic Harrington
825 PointsNic Harrington
825 PointsWhen I remove the
;
at the end of theif
statement I getI'm still a little confused; do I omit the semicolon? And from what you said:
Should I create an else statement? :( I appreciate the help!
Steven Parker
231,275 PointsSteven Parker
231,275 PointsYou don't need an "else" since the function will have already returned otherwise.
But you do need a "
return false;
" at the end to fulfill the requirement of returning a bool.Nic Harrington
825 PointsNic Harrington
825 PointsOh! Got it! Now I know what needs some practice. Thank you! I marked this as the best answer.