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 trialTyler Dotson
Courses Plus Student 1,740 Pointswhy does this not work?
why does numberOfSides not work?
// Enter your code below
class Shape {
var numberOfSides: Int
init(sides: Int) {
self.numberOfSides = numberOfSides
}
}
let someShape = Shape()
3 Answers
David Papandrew
8,386 PointsIt doesn't work because:
1) Your init method should assign the init method's sides parameter to self.numberOfSides (right now you are assigning an undeclared object, numberOfSides)
2) When creating the someShape constant, the init method should take an argument
Here's the corrected code:
// Enter your code below
class Shape {
var numberOfSides: Int
init(sides: Int) {
self.numberOfSides = sides
}
}
let someShape = Shape(sides: 4)
NIKOLA RUSEV
5,293 Pointshi david
i solve the challange but just want to ask you is it matter the name of argument in init? becaouse i solve with init(numberOfSides: Int) { self.numberOfSides = numberOfSides my question is not just for this challenge i mean further in codinig is this correct?
David Papandrew
8,386 PointsHi Nikola,
No the parameter name can be whatever you want. This is not a problem. Only issue is that the Treehouse challenges may want variables/constants and parameters with very specific names at times. In those cases, you will want to follow the instructions exactly or you might not pass the challenge (even though it will work in Playgrounds).
NIKOLA RUSEV
5,293 Pointsthanks