Build a Library Manager - Step 4

Tell us what’s happening:

When I submit this code, it tells me I have to use a higher order function such as (filter, map, reduce.) However, I don’t see how these functions could be beneficial here. I feel like my code does exactly what it asks for. “The function should return a string that contains the title, author, and pages of all the books in the array passed to function.” When I log this function it displays the title, author and pages, but I understand this isn’t what they’re looking for. Coding makes me feel dum

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,
  },
];


// User Editable Region

function displayBooks (arr) {
  return `${arr.title} ${arr.author} ${arr.pages}`
};

// 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/135.0.0.0 Safari/537.36

Challenge Information:

Build a Library Manager - Step 4

Hey, here you are supposed to handle the data within the entire array:

The function should return a string that contains the title, author, and pages of all the books in the array passed to function.

Therefore you need an higher order function.

If you test the function you have written you’ll realize that it doesn’t work because the array itself does not have title, author and pages properties. Those properties belong to each element within the array.

When I log your function
console.log(displayBooks(library));
it returns: undefined undefined undefined

The instructions were not clear to me, when it says “…all the books in the array passed to function” To me that sounds like when you pass one of the objects it should return the title author and pages of that object, but I understand now, it wants ALL of the objects.

Perhaps a better name for this function would be displayAllBooks().

Create a displayBooks function with a parameter accepting an array with book objects

Maybe not the best wording, but it takes an array.