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 trialBalazs Meyrhuber
986 PointsI can´t solve the string interpolation in this excercise
Can somebody please help me to solve this challenge
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 =
RGBColor(red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0)
}
}
4 Answers
Greg Kaleka
39,021 PointsHi Balazs,
You've almost got it, but you need to use string interpolation for the description! We definitely don't want to hard-code in values for the description. If we do that, we could create a RGB color that's 100% blue, and the description would still be the color you hard-coded in. Also, your description is an RGBColor
, but it should just be a simple string. The idea is that someone can call print(myColor.description)
and get an output that describes the color. The example given is that it should print "red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0", but those values should match whatever is in the instance.
Instead, you need to use string interpolation.
self.description = "red: \(), green: \(), blue: \(), alpha: \())"
You know what to fill in inside those parentheses, right? You got this!
Let me know if anything doesn't make sense.
Cheers
-Greg
Balazs Meyrhuber
986 Pointsstruct 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))"
}
}
I changed it now and it still isn´t working what else do I need to do?
Greg Kaleka
39,021 PointsYou got it - you just have an extra closing parenthesis in your string (at the end). Delete that and you're good to go.
Balazs Meyrhuber
986 PointsThank you Greg it worked
Giorgos Karyofyllis
21,276 Points[REMOVED]
Greg Kaleka
39,021 PointsHi Giorgos,
Please refrain from posting answers to challenges without any explanation. It doesn't help students learn!
Instead, try to explain what the student did right, what they did wrong, and maybe provide the solution, but often it's better to let them figure it out with you getting them most of the way there.