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
Arsene Lavaux
4,342 PointsStill getting error in challenge on Swift Function override when no errors in playground!
Getting errors in code challenge when code doesn't show any errors and return proper values in Swift playground. Help!
Here is code:
// Challenge Team Treehouse Override Method
import UIKit
class Button {
var width: Double
var height: Double
init(width:Double, height:Double) {
self.width = width
self.height = height
}
func incrementBy(points: Double) {
width += points
height += points
}
}
class RoundButton: Button {
var cornerRadius: Double = 5.0
override func incrementBy(points: Double = 7.0) {
super.incrementBy(points)
}
}
let rb = RoundButton(width: 5, height: 12)
rb.cornerRadius //5
rb.width //5
rb.height //12
rb.incrementBy()
rb.width //12
rb.height //19
Can also provide screenshots of what the code challenge shows if someone refreshes me on how to achieve that.
Thanks!
1 Answer
Cindy Lea
Courses Plus Student 6,497 PointsTry 10 & 17 for your last 2 values, otherwaise your code matches mine:
class Button { var width: Double var height: Double
init(width:Double, height:Double) {
self.width = width
self.height = height
}
func incrementBy(points: Double) {
width += points
height += points
}
}
class RoundButton: Button { var cornerRadius: Double = 5.0
override func incrementBy(points: Double = 7.0) {
super.incrementBy(points)
}
}
let rb = RoundButton(width: 5, height: 12) rb.cornerRadius //5 rb.width //5 rb.height //12 rb.incrementBy(5) rb.width //10 rb.height //17