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 trial

C#

Nuradin Sheikh
Nuradin Sheikh
6,211 Points

I'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;


    }
}
Isaiah Dicristoforo
Isaiah Dicristoforo
1,135 Points

What 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.

1 Answer

Steven Parker
Steven Parker
231,271 Points

The 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?

:wink: