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 trialIngo Ngoyama
4,882 Pointslet statement confusion
I am confused on the use of let descriptiion= I think we are suppose to write this one with out a function but I have not done so before. Where do we use the let description = String at
struct Paint
{
let red: Double
let green: Double
let blue: Double
let alpha: Double
// 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
}
func Palete( description: String) -> String
{
let description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
return description
}
}
let color = Paint(red: 11.0, green: 22.0, blue: 33.0, alpha: 44.0)
color.Palete(description: <#T##Paint#>)
2 Answers
Chris Stromberg
Courses Plus Student 13,389 PointsI would first add a stored property for the string description to your Struct.
let red: Double
let green: Double
let blue: Double
let alpha: Double
// You need this stored property in your struct.
let description: String
You want to initialize, or assign the description string a value, so you would do this in the init portion of the the struct.
init(red: Double, green: Double, blue: Double, alpha: Double)
{
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
// When we initialize a new object of type Paint, we give its description property this value.
self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
Last call the method on your instance of Paint. Which will return your string.
color.description()
Ingo Ngoyama
4,882 PointsThank you very much I see now to just treat the struct like a completely independent function. But the () on the description call is not needed.
Ingo Ngoyama
4,882 PointsIngo Ngoyama
4,882 PointsWhoops the editor on treehouse did not like it . It must want a string conversion of the color description.
Ingo Ngoyama
4,882 PointsIngo Ngoyama
4,882 PointsHello Chris. The editor for some reason says that the string for description doesn't match the example.