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

Code not working

whenever I run this code I think it will be able to work, but it asks me if I created a method called EatFly. But I have Please Help.

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

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

        EatFly(int distanceToFly)
            bool canEatFly == distanceToFly <= TongueLength;
        return canEatFly;

    }
}

4 Answers

you forgot to put your access modifier (public/private/etc) and return type (String,int,void,etc) before your method, so it is not valid. You should also make sure you appropriately use your open and closing brackets { and }.

This is what I came up with it still doesn't work can you tell me what I did wrong.

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

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

    public int EatFly(int distanceToFly)
    {
        bool canEatFly == distanceToFly <= TongueLength;
    return bool canEatFly;
    }

}

}

above on your answer where you posted code, there are two errors. The first is that when you return a variable (or any time you use a variable that has already been declared) you don't need to specify its type. it should say

return canEatFly;

second error is that your method is returning a bool value, not an int, so you need to declare your method like this:

public bool EatFly(int distanceToFly)
{
// rest of your code goes here
}

Thank you much!