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

Sadettin Senberber
Sadettin Senberber
974 Points

How I create a single int distanceToFly parameter?

I don't crate a single distanceToFly parameter. Is single means 1,3,5 or what? Int parameter for example ฤฑnt distanceToFly ; isn't it or I don't know how it is set up. Please help.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLenght; 

        }
        public EatFly(asd Asd)
        {
            bool distanceToFly <= Asd.tongueLenght;
        }

    }
}

1 Answer

Hi there,

You posted a thread on this earlier - I guess the answer didn't fix your problem.

You have created a new method. You have it taking a parameter. It need to return a bool, so add that keyword before the method name.

The parameter is an int, not an Asd and it needs to be called distanceToFly. That makes your method skeleton look like:

public bool EatFly(int distanceToFly)
{
}

Inside the method, you need to compare distanceToFly to the existing TongueLength. Use less than or equal to so that a Frog can catch a fly if the fly is in range. Return that comparison directly.

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

I hope that helps. Please let me know ow you get on.

Steve.

P.S. If a thread's answer doesn't help you, please say so, rather than creating a new thread on the same issue. This ensures that 1. you get your question answered and 2. other students have a more condensed area where answers lie

Sadettin Senberber
Sadettin Senberber
974 Points

I pass this time thank you very much for your patience and for your time.

Well done on passing the challenge! :+1: :+1: