Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
We've written the `checkOut()` and `returnBook()` methods, but we have an opportunity to take advantage of JavaScript's "setter" methods and should refactor our code.
Instructions for Workspace
Your instructions are as follows:
1) Change the out
property initialization in the Book class constructor method to _out
.
2) Add a setter method called out()
to the Book class. It should receive one argument, a boolean value.
Inside the setter method, set the value of the
_out
backing property to the parameter.Then, inside the setter method, check the value of the
_out
backing property. If it'strue
, calculate the due date and set the Book object'sdueDate
property. If it'sfalse
, set thedueDate
property tonull
.
3) Add a getter method to the Book class called out()
. It should return the value of the _out
backing property.
4) Back in the Patron class, refactor your checkOut()
method to use the new out()
setter method instead of your existing code.
You need to sign up for Treehouse in order to download course files.
Sign up