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

JavaScript Object-Oriented JavaScript Getters and Setters Setters

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

No setter method for activity?

I'm curious as to why we don't have a setter method for activity()?

Is there a reason for this or was there just no reason to demonstrate one in this video?

1 Answer

Joel Bardsley
Joel Bardsley
31,249 Points

For the activity, there wasn't anything to pass as a required argument for a setter method. It just took the current time (in hours) and computed the value based on that.

You could change it to a setter method if you wanted to manually pass a chosen hour as an argument, I guess, but the activity example was useful as it's the sort of value you wouldn't want to attach to the object.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Thanks Joel,

I'm just reviewing this course in prep for the upcoming "By Example" course. I keep thinking we should be getting a matching setter for the activity property and it always throws me that we start a new setter for another property. I think that's just my brain doing the talking but I thought I should ask. :)

Joel Bardsley
Joel Bardsley
31,249 Points

I just happened to go through this course earlier this afternoon. Enjoyed it, looking forward to the 'By Example' one!