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

Nicholas Wallen
Nicholas Wallen
12,278 Points

This part doesn't make sense to me. Can someone explain?

const dateDiff = new Date(now - patron.currentBook.dueDate); const daysLate = dateDiff.getDate();

1 Answer

Hello Nicolas. I will start with improving the readability of your code and explain what is actually going on there.

const dateDiff = new Date(now - patron.currentBook.dueDate);
const daysLate = dateDiff.getDate();

On line 1 of the snippet above, a new variable(dateDiff) was created to store the value of a new Date instance. The Date object's constructor accepts a string argument to create a date equal to the time specified in the string argument. In your case the argument was the difference between the current time(now) and the due date of the patron's current book. Line 2 is quite straight forward. A method on the newly created date instance is invoked to get the day of the month of that date which ranges from 1-31.

Check out the link below for more clarity. 👇 I hope this helps.