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 trialPaul Holder
2,155 PointsI am not quite sure how to assign initial values to the properties. Like in this example with numbers and strings.
I have tried everything I can think of to properly execute this challenge. I understood the video that went with it, but actually assigning values is giving me trouble.
struct RGBColor {
let red: Double
let green: Double
let blue: Double
let alpha: Double
let description: String
// Add your code below
init(redValue: Double, greenValue: Double, blueValue: Double, alphaValue: Double, descriptionValue: String) {
red = redValue
green = greenValue
blue = blueValue
alpha = alphaValue
description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
}
2 Answers
Anusha Singh
Courses Plus Student 22,106 PointsHey Paul, you were almost correct except that you had to use self.(the colour) in the init function, and also mostly programmers write the name of the stored property itself for the init function(Don't add "value" in the parameters). Plus, you don't really need to add "description" in the parameter. Here's the code I used to pass the challenge. Hope it helped
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)"
}
}
Paul Holder
2,155 PointsI greatly appreciate the quick response! This makes sense. However, the challenge is still saying that it was unable to compile the code... Any ideas why this would happen?
Anusha Singh
Courses Plus Student 22,106 PointsHi Paul, I re-submitted my code in the code challenge, if you noticed there was an extra comma in the parameters of the init function which was not needed, after I removed that comma, it worked. Sorry about that though. I hope my answer helped! Regards
Paul Holder
2,155 PointsPaul Holder
2,155 PointsDisregard the last comment. It worked! I appreciate it!!