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# C# Objects Methods Methods

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

what did I do wrong for the next code challenge

I have error in the next code challenge : Frog.cs(11,20): error CS0161: `Treehouse.CodeChallenges.Frog.EatFly(int)': not all code paths return a value Compilation failed: 1 error(s), 0 warnings. This is my code : namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;
    }

   public bool EatFly(int distanceToFly)
   {


    bool EatFly;

   }
}

}

Christopher Eikel
Christopher Eikel
558 Points

Dont worry, I fought with this also. I was overthinking it way to much. especially not knowing the the distance to the fly. But knowing the distance really did not matter. You are Looking for something like this:

namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;

    public Frog(int tongueLength)
    {
        TongueLength = tongueLength;
    }

    public bool EatFly(int distanceToFly)
    {

        if (distanceToFly < TongueLength)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

}

}

3 Answers

Hello!

The error says you have to return a value from the EatFly method. Being a bool method, you have to return a bool value, namely true if the distanceToFly value is equal or higher than the tongueLength attribute or false if its lower.

Hope it helped!

Has anyone managed to get the answer to this? Would be VERY useful for the code questions if there was the facility to show the answer.

Jon Brush
Jon Brush
279 Points

Yeah for real, I just skip them all now because I can never get them right,

Tojo Alex
Tojo Alex
Courses Plus Student 13,331 Points

If any one did that then anyone could type into google enter the name of the code challenge followed by treehouse and they will find anyone's question an they could copy the code that the person who answered the students question (if answered ) paste it and easily pass though if it is explained in words that person wouldn't be bothered to read so they would move on but you do have a point. Hopefully you get my point.