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

Dan Ingenthron
Dan Ingenthron
8,769 Points

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.