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 trialBarry Ort
12,373 Pointswhat's the correct answer?
I can't figure out what the correct answer is.
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; }
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Polygon
{
public int NumSides { get; private set; }
public Polygon(int numSides)
{
NumSides = numSides;
}
}
}
Barry Ort
12,373 PointsI've been working in this for a few days now and I've tried out a bunch of things that didn't work. I followed the error messages that are displayed on preview and this one had the least errors (only 1).
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; }
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
public double Area
{
get
{
return SideLength *= SideLength;
}
}
}
3 Answers
Patricia Hector
42,901 PointsCheck it from inside to outside -your SideLength property is closed, you have two curly brackets { ...} -your constructor (Square) is closed as well, two curly brackets {...} -your Area property and class Square have two -but your namespace has one open curly bracket but there is not a close curly bracket
You can also use a trick: count how many open curly brackets and close curly brackets you have. If the result is the same, everything is fine if it's not, then check your work again. In this case, just add one to the end of the document.
Barry Ort
12,373 PointsFantastic you were right! Thatnk s lot!
Steven Parker
231,275 PointsYou're really close there.
There was originally a closing brace on line 10, but it seems to have gone missing. Be sure to put it back.
But you also don't want to use a multiplication assignment operator ("*=
") in your computed property. This permanently changes the value of SideLength. All you need is an ordinary multiplication operator ("*
").
The challenge might let you get away with it, but it shouldn't. That's actually a bug in the challenge and you might want to report it to Support.
Patricia Hector
42,901 PointsEverything is fine Barry, you are just missing a curly bracket after your property.)
Barry Ort
12,373 Pointsbesides the one that is under it?
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIt doesn't look like you've written any code yet.
At least please give it a good-faith attempt and then ask for help if you have trouble.
And as a hint: the area of a square is side length multiplied by itself.