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

Is the code meant to charge the same fine for each day the book is late?

By adding a multiplier for 'days late', this seems to be set up to charge $.10 the first day, $.20 the 2nd day, $.30 the 3rd day, and so on. By 'daily fine' I understood the code to be a little simpler, like this:

chargeFines() {
    const now = new Date();

    const latePatrons = this.patrons.filter(patron => 
        (patron.currentBook !== null && patron.currentBook.dueDate < now)
    );

    for (let patron of latePatrons) {
        patron.balance += this.dailyFine;
    }
}

This adds a $.10 daily fine to the patron's balance until the book is returned. This is a small detail, but just including in case anyone else read the problem this way.

1 Answer

The instructions specify:

dailyFine ... charged to each Patron for every day their checked out book is overdue

So there is a fine for each day which is why the multiplier is used.

Jeremy Yochum
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Yochum
Front End Web Development Techdegree Graduate 16,023 Points

If you use the multiplier by having patron.balance += this.dailyFine * daysLate; then after a year you would have to pay $6,679.50 for that book. Just take the plus sign off to reassign the property with the new value.