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