Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Practice Object Interaction Checking Out and Returning a Book Solution: Charging Fines to Patrons

Faraz Khalid
Faraz Khalid
4,077 Points

Practice 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?

Amir Shahabnia
Amir Shahabnia
29,310 Points

Hey 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.

1 Answer

dueDate is a key in the currentBook object.