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 trialNuradin Sheikh
6,211 PointsI'm having an issue returning a value on the third coding task?
The question asks "Add another method named EatFly that takes two integer parameters and returns a boolean value. Name the parameters distanceToFly and flyReactionTime. Return true if the frogβs tongue is longer (i.e. greater) or equal to than the distance to the fly and its reaction time is faster (i.e. less) or equal to than the flyβs reaction time.". The error I always end up getting `Treehouse.CodeChallenges.Frog.EatFly(int, int)': not all code paths return a value. Can someone point me in the right direction? The code snippet is below:
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength , int reactionTime)
{
TongueLength = tongueLength;
ReactionTime = reactionTime;
}
public bool EatFly(int distanceToFly , int flyReactionTime ){
if (TongueLength >= distanceToFly && ReactionTime <= flyReactionTime){
return true;
}
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
public readonly int ReactionTime;
}
}
1 Answer
Steven Parker
231,271 PointsThe function is declared to always return a "bool" value.
Currently, the function returns "true" (which meets that requirement) when the test conditions are met ...
but what does it return when the conditions are not met?
Isaiah Dicristoforo
1,135 PointsIsaiah Dicristoforo
1,135 PointsWhat will happen if the condition in the if-statement is false? Currently, you don't have anything happening. Your method needs to return something (a boolean value) if the conditions in the if statement are not true.