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 trialXun Huang
Web Development Techdegree Graduate 18,515 PointsWHY 'patron.balance += this.dailyFine * daysLate' ???
I don't understand , because getDate() means get the day of the month, it not a difference between now and the dueDate, it always returns a number between 1 and 31, and what if a patron overdue for 100 days? And why use '+=' instead of '=' , shouldn't we calculate an integer first then times the overdue day?
1 Answer
Steven Parker
231,261 PointsThe use of "+=" would add the fine to any current balance in the account, so that's probably intended.
But converting the difference between two dates into a date itself isn't really valid as a concept, though it might seem to work as long as the difference was less than a month. A more appropriate way to calculate a difference would be:
// difference in ms / ms per day
const daysLate = Math.floor((now.getTime() - patron.currentBook.dueDate.getTime())
/ (1000*60*60*24));
You might want to make a bug report directly to the staff as described on the Support page. If you're the first to report it, it should get you the special Exterminator badge.
Xun Huang
Web Development Techdegree Graduate 18,515 PointsThank you! That makes much more sense!
Caleb Kemp
12,755 PointsCaleb Kemp
12,755 PointsAfter checking out the code myself, it would seem that you are correct. You could tag the instructor and see if they have an explanation, but I'm of the opinion that it was probably just an oversight. Great job noticing that though.