C# C# Objects Methods Methods

Heather Barton
Heather Barton
658 Points

else/if statements

I'm not sure what I'm doing wrong here - the compiler seems to be telling me that I'm using a '=' when I shouldn't be. Am I using 'return' in the wrong way?

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
        public bool EatFly(int distanceToFly)
        {
            TongueLength = tongueLength;

            if (tongueLength >= distanceToFly)
            {
                return = true;
            }
            else
            {
                return = false;
            }
        }
    }
}

2 Answers

Steven Parker
Steven Parker
182,307 Points

It sounds like you already figured part of it out — there's no "=" in a "return" statement. Also:

  • the "tongueLength" was a constructor parameter. You don't have (or need) access to it in this function
  • the "TongueLength" you want to compare with is the one with capital "T"
Heather Barton
Heather Barton
658 Points

got rid of the '=' and made "tongueLength" and internal variable and that worked, thank you!

Steven Parker
Steven Parker
182,307 Points

Heather Barton — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

Steven Parker
Steven Parker
182,307 Points

I'm not sure what you mean by made "tongueLength" and internal variable. The lower-case-"t" variable is only used as a constructor parameter, you don't need it again. And this line from the constructor does not need to be in the other function at all:

            TongueLength = tongueLength;