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 trialDanny Kilkenny
4,507 PointsWhy self.strength instead of just strength
I don't understand why Pasan uses "self.strength" instead of just using "strength". Could someone explain that to me. Here's the code below
1 Answer
Gabriel Mititelu
5,881 PointsHello, Danny.
Whenever you need to access/use an object's property within that object's definition, you must use the keyword self and dot notation.
To put this into perspective, when you want to access the strength property outside the Tower object, what do you do ?
You write:
Tower.strength
Similarly, when you need to access/use the strength property within the object, you write :
self.strength
Hope this helps. However, if it doesn't, do ask away.
Danny Kilkenny
4,507 PointsNah that makes perfect sense! Thanks!
Danny Kilkenny
4,507 PointsDanny Kilkenny
4,507 Points