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 trial

iOS

jon kelson
jon kelson
5,149 Points

RGBcolor

hi please could you tell me what im doing wrong

โ€‹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)" }
}

jon kelson
jon kelson
5,149 Points

sorry its all Squashed up

3 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Jon,

you almost got it right but there's only one tiny mistake: You have to interpolate the constants inside of the description String with a backslash instead of a forward slash like so:

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)" 
  }
}

I hope that helps! :)

I pasted it into Xcode and it looked good except for one very strange issue. struct didn't turn purple, like it should. So I deleted it and retyped it and it turned purple. Also, there were 4 typos. String interpolation is (...), not /(...):

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
        description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
    }
}

//if I remember correctly colors have to be fractions with divisors of 255
let color = RGBColor(red: 23/255, green: 235/255, blue: 155/255, alpha: 0.8)
color.description

This displays:

"red: 0.0901960784313725, green: 0.92156862745098, blue: 0.607843137254902, alpha: 0.8"
jon kelson
jon kelson
5,149 Points

Ok thanks jcorum I'll try that later aswell . Many thanks

jon kelson
jon kelson
5,149 Points

Ahh thanks Tobias I should know that by now !