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 trialTojo Alex
Courses Plus Student 13,331 PointsI don't know if i have to assign it to anything
It asks me to Add a constructor to the Frog class that accepts a tongue length parameter value. Though I don't know if I have to assign it with variable.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
}
}
10 Answers
Steven Parker
231,248 PointsFor task 2 it's enough just to accept the parameter, the constructor body can be empty.
In task 3 you'll be asked to use the parameter to initialize the field.
Tojo Alex
Courses Plus Student 13,331 Pointsthat is what I do in task 2 but still there's an error : Frog.cs(5,30): error CS0106: The modifier `readonly' is not valid for this item Compilation failed: 1 error(s), 0 warnings
Tojo Alex
Courses Plus Student 13,331 PointsI enter the curly brackets though it gives me that error
Steven Parker
231,248 PointsThe code sample above shows task 1 completed, but no code for task 2 yet.
If you're having an issue with task two, please show the code with the task 2 changes included.
Tojo Alex
Courses Plus Student 13,331 Pointsyou are right I didn't do much of a difference though to me it looks right to me. thanks for trying your best to explain though I still am not 100% sure what I did wrong could show me the code so I could refer.
Steven Parker
231,248 PointsCheck out the video example, where a constructor is created for the "Map" class.
Tojo Alex
Courses Plus Student 13,331 PointsOK now this is what I done: namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;
Frog(int TongueLength)
{
}
}
} The error now is :Did you declare the 'Frog' constructor with the 'public' access modifier?
Steven Parker
231,248 PointsBased on the error message, you might try putting the word "public" in front of the constructor name "Frog".
And when posting code, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
Tojo Alex
Courses Plus Student 13,331 Pointsthanks alot
Tojo Alex
Courses Plus Student 13,331 PointsNow in challenge 3 It says: Frog.cs(10,35): error CS0103: The name `tonguelength' does not exist in the current context Compilation failed: 1 error(s), 0 warnings Code: namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;
public Frog(int TongueLength)
{
TongueLength = tonguelength;
}
}
}
Steven Parker
231,248 PointsThe parameter name should be "tongueLength" (little "t", capital "L"). But at the moment it has a capital "T" in the definition, and a little "l" in the assignment.
For any future questions, please format your code using the instructions/video I mentioned previously.
Tojo Alex
Courses Plus Student 13,331 Pointsthanks I figured it out
Tojo Alex
Courses Plus Student 13,331 Pointsnamespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength; {
}
}
}
Steven Parker
231,248 PointsOther than the lack of formatting, The only difference I can see is a pair of braces.
But a constructor will look much like a method, with a name, arguments with specified types in parentheses, and then braces enclosing a code block. You may want to take another look at the example built in the Initialization video, starting about 20 seconds in.
And when posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.