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 trialoliverchou
20,886 PointsI couldn't figure out what's going on! Anyone help me?
I cannot distinguish between "self" properties and others. And I don't know wheher to put the "discription assinment" statement , in the "init" or create another "method" or simply inside the "struc"?
struct RGBColor {
let red: Double
let green: Double
let blue: Double
let alpha: Double
let description: String
// Add your code below
init(red: Double, green:Double, blue:Double, alpha:Double, discription: String) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
self.discription = "red: " + red + ",green: " + green + ",blue: " + blue + ",alpha: " + alpha
}
}
2 Answers
Steve Hunter
57,712 PointsHi there,
A couple of things - first, you don't want to pass the description
in as a parameter to the init
method. You create description
within init
. Second, spell description
correctly - that'll stop confusion between the top of the struct and your init
method.
Lastly, maybe consider using interpolation to construct your description
string. That all looks like:
init(red: Double, green: Double, blue: Double, alpha: Double) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
I hope that helps.
Steve.
Cory Norell
10,613 PointsAhhh, I see. That makes perfect sense when you explain it that way. Thank you Steve!
Steve Hunter
57,712 PointsNo problem!
oliverchou
20,886 Pointsoliverchou
20,886 Pointsthanks a lot!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem!
Cory Norell
10,613 PointsCory Norell
10,613 PointsSteve, your answer to this question just helped me complete the code challenge, so thank you! I was running into issues - I thought I had tried everything - until i stopped including description as a parameter.
My question is, why do we create the description inside the init rather than passing it as a parameter?
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHi Corey,
I'm glad my answer helped!
There is no need to pass in
description
as a parameter as it is made up of the other parameters. To pass it in would duplicate typing without adding anything.Does that make sense?
Steve.