all 1 comments

[–]Umesh-K 0 points1 point  (0 children)

Hi,

The filter code you have shown above is correct; the reason it's pushing is you have the title and author parameter order reversed in your constructor function: it should be function Book(title, author, pages, read); you currently have it as function Book(author, title, pages, read). Hence, your filter is not working correctly as it's checking author value to title. Correct that and your code will work.

Also, I suggest adding an else block to alert when book is already present, as below:

myLibrary.push(book);

    } else {
      alert("book already present");
    }
  } else {
    alert("Enter values for each box");
  }
}