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

Benneth Paredis
Benneth Paredis
4,597 Points

Quick Question

What am i doing wrong in this excercise , its supposed to return true if the tongueLength is less or equal to the distance of the fly.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
            bool EatFly = int distanceToFly <= tongueLength;
        }
    }
}
Lewis Gilbert
Lewis Gilbert
2,082 Points

Hi, at the moment you are not specifying a return type e.g. Bool, String, Int etc... for your method. In this case you are looking to return a bool.

"int distanceToFly" doesn't actually hold a value nor is it initialized.

Finally you need to use the "return" keyword to return a value to the method caller!

Below is a working solution that i have made for you :) Thanks

public bool Frog(int tongueLength)
        {
            int distanceToFly = 10;
            bool eatFly = distanceToFly <= tongueLength;
            return eatFly;
        }

What error message are you getting?

Do you have a Main Method? Are your variables assigned?

The int distanceToFly variable has not been declared/assigned properly

Here is the correct code below:

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

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

public bool EatFly( int distanceToFly)
{
    bool ableToEat = TongueLength >= distanceToFly;
    return ableToEat;
}
}

}

Benneth Paredis
Benneth Paredis
4,597 Points

It keeps saying "Did you create a parameter in your method named distanceToFly?" even after i wrote the code that you send me.

Edit: nevermind i got it now, thanks alot !

1 Answer

I'm glad that I'm able to help.