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

My chargeFines method

My chargeFines method is this:

chargeFines = () => {
        this.patrons.filter(patron => patron.out)
            .forEach(patron => {
                const today = new Date();
                if (today > patron.currentBook.dueDate) {
                    const day = today.getDate();
                    const due = patron.currentBook.dueDate.getDate();
                    const daysLate = day - due;
                    patron.balance = daysLate * this.dailyFine;
                }
        });
    }

I think it is actually a more elegant solution than Ashley's, but could someone with more experience critique it and tell me if I am on the right track? Thanks!

1 Answer

Steven Parker
Steven Parker
229,744 Points

Did you test this? I'm wondering because arrow functions do not define a "this" like conventional functions do.

After I posted this I did end up testing it and it does produce the desired behaviour. However I am now wondering if there is a more efficient way of writing the function. Steven do you think you could point me to a resource you know of explaining this in the context of arrow functions?

Steven Parker
Steven Parker
229,744 Points

MDN is my "go to" reference for all things front-end. Here's the page on Arrow Functions.
Look for the highlighted section titled "No separate this".

But also note that MDN advises "Arrow function expressions are ill suited as methods..."

Thank you very much.