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 trialBekzod Rakhmatov
7,419 PointsCan AnyOne explain the problem I did not quite get it?
I am reading the problem but I can not understand what it said is there anyone who can help me?
struct RGBColor {
let red: Double
let green: Double
let blue: Double
let alpha: Double
let description: String
// Add your code below
}
1 Answer
Mitchell Richmond
5,401 PointsIt wants you to create an initializer method, so when you create an instance of the Struct you have to put in the values for red, green, blue, and alpha. It also wants you to initialize the description constant as a String that concatenates all of the color values together.
So for example, once I create my instance method, I can create an instance of the Struct by saying something like: let color = RGBColor(red: 23, green: 23, blue: 23, alpha: 1) Then, I can say: color.description and it would return: "red: 23.0, green: 23.0, blue: 23.0 alpha: 1.0".
The whole solution looks like this:
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)")
}
}
Let me know if that makes sense if not I will do my best to help you out!
Bekzod Rakhmatov
7,419 PointsBekzod Rakhmatov
7,419 PointsI got it I did as you shown but it was not accepted and copied your and paste it accepted I think something is going wrong with me :) Thanks Bro