I am getting an error when I invoke a prototype function inside of a loop.
The class
var Book = function(title, Available, publicationDate, checkoutDate, callNumber, Authors) {
this.title = title;
this.Available = false;
this.publicationDate = new Date();
this.checkoutDate = checkoutDate;
this.callNumber = 690080;
this.Authors = Authors;
};
Other class with has the booksOut array property
var Patron = function(firstName, lastName, libCardNum, booksOut, fine) {
this.firstName = firstName;
this.lastName = lastName;
this.libCardNum = libCardNum;
this.booksOut = [];
this.fine = 0.00;
};
The prototype which is supposed to add the book to the array property in the patron class
Patron.prototype.read = function(Book) {
this.booksOut.add(Book);
}
The loop that cause the TypeError: catalog[k].read is not a function error with the parenthesis and without them it always gives the same output.
for (var i = 0; i < 90; i++) {
for (var j = 0; j < catalog.length; j++) {
for (var k = 0; k < patrons.length; k++) {
var fine = patrons[k].fine;
if (catalog[k].Available) {
catalog[k].checkOut();
} else {
catalog[k].checkIn();
catalog[k].read();
if (catalog[k].isOverdue()) {
fine = fine + 5.00;
}
}
patrons[k].fine = fine;
}
}
}
Any help would be appreciated.
catalog? It it is an instance ofBookthen it does not have thereadmethod, which is defined forPatron, notBook. Also, it seems to expect an argument.... Calling that parameterBookis not the best choice, as it can be misunderstood as being theBookconstructor. Use init-caps only for constructors/classes.