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 Object-Oriented Programming Initialization

it's throwing no errors and my only clue is "Bummer! try again" so i assume i'm completely off base.

is this not how you initialize the object with a value?

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

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

        Frog frog = new Frog(3);
    }
}

1 Answer

Steven Parker
Steven Parker
231,198 Points

:point_right: It looks like you are creating a new local variable named TongueLength inside the constructor, instead of initializing the property of the same name that you have already defined. That's not an error to the compiler, it just doesn't do what the challenge asked for.

So, instead of this:

          int TongueLength = tongueLength;

Just do this:

          TongueLength = tongueLength;

And remove this line, it's not part of the challenge:

        Frog frog = new Frog(3);

-sp:sparkles:

it will accept the line that you are telling me to change. Third step "Add a constructor to the Frog class that accepts a tongue length parameter value." is what i am trying to achieve? is the line your telling me to remove not meant to do that?

Steven Parker
Steven Parker
231,198 Points

You obviously passed task 2 already, perhaps you didn't realize that the "constructor ... that accepts a tongue length parameter value" is this part:

        public Frog (int tongueLength)  // constructors have the name of the class and no type
        {
        }

That extra line would create an instance of this class and name it frog. That's certainly not something you would do inside the class itself.

apparently was doing the third step with the second. thank you for your help!