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 trialJon Schenck
2,028 PointsHelp me understand
What is the correct code and why?
class Button {
var width: Double
var height: Double
init(width:Double, height:Double){
self.width = width
self.height = height
}
func incrementBy(points: Int) {
}
}
1 Answer
Chase Marchione
155,055 PointsHi Jon,
The challenge wants us to add the points parameter (or, really, the value of that variable) to the current values of width and height.
1) We'll want the points parameter to be of type Double, because width and height are both of type Double. 2) Now we can add 'points' to width and height. Instead of typing out, for example, 'width = width + points', I'll use the assignment operator += and type 'width += points', which means the same thing programmatically.
func incrementBy(points: Double) {
width += points
height += points
}
Hope this helps!
Jon Schenck
2,028 PointsJon Schenck
2,028 PointsGot it! Thanks for the help.