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!

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

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.