Back to Freecodecamp

Step 8

curriculum/challenges/english/blocks/workshop-library-manager/6822595203b35c00b87c0524.md

latest3.1 KB
Original Source

--description--

The array of book titles is nice, but it would be nice to display the title and author for each book like this:

js
[ 
  "Your Next Five Moves: Master the Art of Business Strategy by Patrick Bet-David and Greg Dinkin",
  "Atomic Habits by James Clear",
  "Choose Your Enemies Wisely: Business Planning for the Audacious Few by Patrick Bet-David",
  ...
]

Update your use of the map() method to instead return an array of strings in this format: TITLE by AUTHOR.

You will need to use either template literals or string concatenation with the + operator to achieve this result.

--hints--

Your getBookInformation function should return an array.

js
assert.isArray(getBookInformation(library));

Your getBookInformation function should return an array of strings with the title and author for each book.

js
const testLibrary = [
  {
    title: "Title A",
    author: "Author A",
    about: "About A",
    pages: 320,
  },
  {
    title: "Title B",
    author: "Author B",
    about: "About B",
    pages: 320,
  },
  {
    title: "Title C",
    author: "Author C",
    about: "About C",
    pages: 304,
  },
];

const expected = [
  "Title A by Author A",
  "Title B by Author B",
  "Title C by Author C"
];

assert.deepEqual(getBookInformation(testLibrary), expected);

--seed--

--seed-contents--

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

console.log("Books in the Library:\n");

--fcc-editable-region--
function getBookInformation(catalog) {
  return catalog.map(book => book.title);
}
--fcc-editable-region--

console.log(getBookInformation(library));