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 (What if... declaring multiples)

So going through the library app, we are at this stage:

 const library = new Library();
 const book = new Book('Harry Potter and the Sorcerer\'s Stone', 'J.K. Rowling', '978-0439708180');
 const patron = new Patron('Joe Dirt', 'j.dirt@dmail.com');

    library.addBook(book);
    library.addPatron(patron);

My question is, if you were to have multiple different books, and patrons, what would the best practices be around declaring the variables? If you had two patrons, even if their values were different, they could not share the same const name declaration. (Another problem I just thought of was of multiples of the same book, but that is a less important question at this time.)

1 Answer

I would consider using an array and call it patrons. That way you can have 1+ patrons stored.

Oh that's a great idea! And then you can just access it by it's index value - brilliant. Thank you!