// constructor function
function Book(title, author, pages, read = false) {
this.title = title;
this.author = author;
this.pages = pages;
this.read = read;
this.status = function() {
console.log(this.read);
}
}
// array to store objects
let mybooks = [];
// instances of the Book object
let book1 = new Book('Hello', 'John', 123, true);
let book2 = new Book('Hey', 'Jane', 13, false);
let book3 = new Book('Hi', 'Mary', 12, true);
let book4 = new Book('Holo', 'Peter', 10, false);
let book5 = new Book('Banda', 'Banda', 03, true);
// push the instances to the mybooks array
mybooks.push(book1);
mybooks.push(book2);
mybooks.push(book3);
mybooks.push(book4);
mybooks.push(book5);
// store mybooks to the localStorage
localStorage.mybooks = JSON.stringify(mybooks);
// retrieve data from the localStorage
let data = JSON.parse(localStorage.getItem('mybooks'));
// call the status() method on each object
data.forEach(book => {
book.status();
});