C# C# Objects Methods Methods

It wont work and i have been trying for a long time

I don't know can someone point me in the right direction

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
         public bool EatFly(int distanceToFly)
        {
            bool reach;
            if ( distanceToFly <= tongueLength)
            {
                reach = true;
            }
            else ()
            {
                reach = false;
            }

             return reach;
        }
    }
}

You have to put TongueLength because it is global and can be used anywhere inside the class. and you have to remove the parenthesis at the end of else.

1 Answer

Antonio De Rose
Antonio De Rose
20,860 Points
//the approach is fine, almost there
//if not for 2 mistakes

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
         public bool EatFly(int distanceToFly)
        {
            bool reach;
            if ( distanceToFly <= tongueLength) //error number 1, can you access tongueLength, 
//it has got a different scoping, that is of a different function, 
//you cannot access a variable which is residing in a different function, 
//but you can access the property / variable which is mentioned, just after the class Frog
            {
                reach = true;
            }
            else () //error number 2, why do you need parenthesis, just after else
            {
                reach = false;
            }

             return reach;
        }
    }
}