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 trialFaraz Khalid
4,077 PointsPractice Object Interaction
patron.currentBook.dueDate
How does this access the due date for the currentBook borrowed by the patron when there is no property for dueDate in the patron class?
1 Answer
Zimri Leijen
11,835 PointsdueDate is a key in the currentBook object.
Amir Shahabnia
29,310 PointsAmir Shahabnia
29,310 PointsHey Faraz,
So the Patron class has a property named currentBook which is set to null when we create an instance of the Patron class.
When a patron checkouts a book, the currentBook property will be set to a book object. So now, the currentBook property of the patron object holds a value which is a book object the patron did checkout.
so until now, patron.currentBook refers to the book the patron checkouts (this book has different properties and dueDate is one of them). In the Book class, we have a dueDate property which we did set when a patron checkout a book.
As a result, patron.currentBook.dueDate refers to the due date of the the book a patron checkout.