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 trialAlex Nelsen
Courses Plus Student 2,977 PointsI need help solving this custom initializer problem.
It appears that I have no errors in my coding, but this does not satisfy the problem. Any help here would be appreciated.
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) {
self.red = 86.0
self.green = 191.0
self.blue = 131.0
self.alpha = 1.0
self.description = "red"; "green"; "blue"; "alpha"
}
}
1 Answer
Steven Deutsch
21,046 PointsHey Alex Nelsen,
You have your initializer set up properly, however, you are not assigning the right values inside of it. First, you should be using the parameter names associated with the values you are passing into the initializer to set the values of your RGBColor struct. Second, for the description property you want to initialize it to a string using the red, green, blue, and alpha values passed into the initializer. You can do this by using string interpolation with the parameter names.
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) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
}
Good Luck!
Tyler Renfro
15,190 PointsTyler Renfro
15,190 PointsHow is this returning "red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0"?
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsHey Tyler,
You would pass in those values when you use the initializer. I don't think the challenge wants you to initialize with those specific values. I think it is just using them as an example to display what your initializer should look like.