Build a Library Manager - Step 6

Tell us what’s happening:

Not able to pass test. Error states I need to return an array. I used

console.log(Array.isArray(getBooksByAuthor(library, "Arvid Kahl")))

to check my return and it shows true meaning there is an array coming back with the list of books. Not sure what I am missing.

Your code so far

const library = [
  {
    title: 'Your Next Five Moves: Master the Art of Business Strategy',
    author: 'Patrick Bet-David and Greg Dinkin',
    about: 'A book on how to plan ahead',
    pages: 320,
  },
  {
    title: 'Atomic Habits',
    author: 'James Clear',
    about: 'A practical book about discarding bad habits and building good ones',
    pages: 320,
  },
  {
    title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
    author: 'Patrick Bet-David',
    about:
      "A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
    pages: 304,
  },
  {
    title: 'The Embedded Entrepreneur',
    author: 'Arvid Kahl',
    about: 'A book focusing on how to build an audience-driven business',
    pages: 308,
  },
  {
    title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
    author: 'Jon Gordon',
    about: 'A book about effective ways to lead a coffee bean lifestyle',
    pages: 256,
  },
  {
    title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
    author: 'Jeff DeGraff and Staney DeGraff',
    about: 'A book on how to develop creativity and  innovation skills',
    pages: 168,
  },
  {
    title: 'Rich Dad Poor Dad',
    author: 'Robert Kiyosaki and Sharon Lechter',
    about: 'A book about financial literacy, financial independence, and building wealth. ',
    pages: 336,
  },
  {
    title: 'Zero to Sold',
    author: 'Arvid Kahl',
    about: 'A book on how to bootstrap a business',
    pages: 500,
  },
];

function displayBooks(catalog) {
  let output = 'Books in the Library:\n';

  catalog.forEach((book) => {
    output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
  });

  return output;
}

function getBookSummaries(catalog) {
  return catalog.map((book) => book.about);
}


// User Editable Region

function getBooksByAuthor(books, author) {
  return books.filter((book) => book.author.toLowerCase() === author.toLowerCase()).map((book) => book.title)
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Build a Library Manager - Step 6

I think there may be something wrong with the testing, because it tests with assert.isArray(getBooksByAuthor(library)) (equivalent to your Array.isArray(getBooksByAuthor(library))

that function call is missing something, or the requirements are missing that it should work even without an author name. I will open a bug report

Thank you. I looked ahead to the next step and saw that the solution didn’t have the .map() method. So it was wanting an array of the complete objects that match the filter specified. I also needed to remove the .toLowerCase() method in order for it to pass this step.

while not returning the whole object was an issue, using toLowerCase should not make the tests fail without reason.
with you using this, when the function is called you get an error TypeError: Cannot read properties of undefined (reading 'toLowerCase') because author is undefined.

I’m not sure I understand. I was using the .toLowerCase() method here:

function getBooksByAuthor(books, author) {
 return books.filter((book) => book.author.toLowerCase() === author.toLowerCase())
}

to make the check case-insensitive but, the tests were failing. author is getting defined by the parameter being passed to the function.

not in the test, that’s why I am opening a but report, like I said here:

the TypeError for author being undefined is from the test

Oh, I got you. Thanks for the help.