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 trialHermes Crespo
980 PointsI am doing exactly what the challenge is asking me to do which is to use the constructor to initialize the field ...
... TongueLength. So why am I getting the feedback "Bummer! Does your constructor..."???
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int TongueLength)
{
TongueLength = TongueLength;
}
}
}
3 Answers
behar
10,799 PointsHey Hermes! As steven pointed out, the field and the arguement for the constructor could be called two different things, in order for you to pass this challenge. Because of the concept of scope your currently just saying that the arguement in the constructor should be equal to the arguement, but you should be setting the actual field.
Another way to do this is to use the 'this' keyword:
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int TongueLength)
{
this.TongueLength = TongueLength; // this.TongueLength is talking about the field TongueLength.
}
}
}
Hope this helps!
Hermes Crespo
980 PointsThanks everyone. I will try the "this" thing.... but... how was I supposed to know that if the session did not covered that concept??
Steven Parker
231,248 PointsI suggest changing the argument name instead. That would make it like the examples that were shown in the video.
Levente Bito
4,679 PointsThere is some kind of issue here, because even though I answer correctly or using the this method, I get the error. This isn't the first issue here, I've had the same issue with the previous challenge. There something wrong with the program/website.....
behar
10,799 PointsHey Levnte! I seriously doubt that mate, try posting your code here so we can spot your typo ;)
That being said if you really do belive you have discovered a bug, you should contact staff directly.
Hermes Crespo
980 PointsHermes Crespo
980 PointsThanks a million !! :)
Steven Parker
231,248 PointsSteven Parker
231,248 PointsThat might work, but it's a different practice than what is shown in the course examples.