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 trialharleythomas
16,512 PointsCan't assign default value to "points" parameter
I'm trying to assign the value "7.0" to the points parameter as it's done in the video, but it's giving me an error.
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){
width += points
height += points
}
2 Answers
Michael Liendo
15,326 PointsHello there :) without seeing the exact error, I'll have to go off of the code available. You actually don't have to put double = 7.0 since points is already declared to expect a double. Simply func incrementBy(points: 7.0) should get you bug-free :)
Hope that helps! If it did, upvotes are always appreciated!
Happy Coding,
-Michael
Michael Liendo
15,326 PointsFrom what I can see you're missing your closing bracket for your overridden incrementBy function. The code is running fine in my playground.
harleythomas
16,512 Pointsharleythomas
16,512 PointsHi Michael,
Thank you for your help. I'm getting the same error your way as well. The error is: "You didn't add the 'incrementBy' method to the Class 'RoundButton' "
It seems like if I assign a default value to the points parameter, it thinks I'm not overriding the increment method from the Button superclass. Maybe because the signature is different?