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 Je
4,435 Points[SOLVED] Still stuck..
Can't set the colour of the lamp in the implementation of the method. Is the implementation on the call statement at the very end with Var? Or is it in the func section within the WifiLamp class that I would have to implement the new colour? I tried both but not working.. Thanks for any help!
protocol ColorSwitchable {
func switchColor(color: Color)
}
enum LightState {
case On, Off
}
enum Color {
case RGB(Double, Double, Double, Double)
case HSB(Double, Double, Double, Double)
}
class WifiLamp: ColorSwitchable {
let state: LightState
var color: Color
init(state: LightState, color: Color) {
self.state = .On
self.color = .RGB(0, 0, 0, 0)
}
func switchColor(color: Color) {
self.color = color
}
}
var changedWifiLight = WifiLamp(state: .On, color: .RGB(20.0, 30.0, 20.0, 1.0))
4 Answers
Cindy Lea
Courses Plus Student 6,497 PointsI passed the challenge using all your code except the last name where you declare another variable. The code should look like this:
// Declare protocol here
protocol ColorSwitchable {
func switchColor(color: Color)
}
enum LightState {
case On, Off
}
enum Color {
case RGB(Double, Double, Double, Double)
case HSB(Double, Double, Double, Double)
}
class WifiLamp {
let state: LightState
var color: Color
init() {
self.state = .On
self.color = .RGB(0,0,0,0)
}
}
Moderator Edited: Added markdown to response so it can be read properly in the Community.
Paul Je
4,435 PointsFigured it out!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! lol
Jason Anders
Treehouse Moderator 145,860 PointsWas just about to type out the answer/explanation for you. :)
Glad you got it figured out! Marked your Title as solved.
Paul Je
4,435 PointsStill doesn't work lol, now I'm a little more confused however - it's weird since one other member mentioned the func function is required to pass... but yours doesn't include it, nor the type declared in the protocol to be the one for WifiLamp
Paul Je
4,435 PointsDriving me crazy lol. I'm on task 2, which probably should have been said initially sorry
Paul Je
4,435 PointsPaul Je
4,435 PointsFor future readers, the function should be declared within WifiLamp in order to declare it as the protocol type in addition to Cindy's code
MIchael Montoya
3,222 PointsMIchael Montoya
3,222 PointsThis is the correct answer for only the first part of the problem. (1 of 2)