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#

"Use the constructor to initialize the TongueLength field to the value passed in." Help please

I passed step 2of3 with the code

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

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

But now cannot initialize. I thought perhaps adding:

Frog frog = new Frog(2);

But this does not let me pass the stage.

4 Answers

You can initialize value in constructor using

namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public Frog(int length=4)
        {
        TongueLength=length;
        }
    }
}
Steven Parker
Steven Parker
231,236 Points

You forgot to include a link to the challenge, but if I guessed correctly it is this one.

You code looks good as is (nothing needs to be added), so I tested it in the challenge.

:point_right: I cut and pasted it directly into the challenge and it passed all 3 tasks.

I'm not sure why it didn't pass for you. I suggest just giving it another try.

Jason Land
Jason Land
5,827 Points

The quiz on this isn't using the answer provided by the video to solve it. What the video teaches us would be this:

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

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

    Frog frog = new Frog(2);
}

}`

But this is what passes the test: `namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;

    public Frog(int tongue = 4)
    {
    TongueLength = tongue;
    }
}

}`

WHAT IN THE WORLD I was stuck for ages on that challenge and I had literally the same code as you and it was not working and then I copy-pasted as Steven said and it worked 0_o