Build an fCC Authors Page - Step 8

Tell us what’s happening:

I keep getting this error: 3. When the displayAuthors function is called with an author’s array, it should add a card for each author to the authorContainer div.
How can I fit my code to make my code pass so I can continue onward.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>freeCodeCamp News Author Page</title>
    <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
    <h1 class="title">freeCodeCamp News Author Page</h1>

    <main>
      <div id="author-container"></div>
      <button class="btn" id="load-more-btn">Load More Authors</button>
    </main>

    <script src="./script.js"></script>
  </body>
</html>
/* file: styles.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --main-bg-color: #1b1b32;
  --light-grey: #f5f6f7;
  --dark-purple: #5a01a7;
  --golden-yellow: #feac32;
}

body {
  background-color: var(--main-bg-color);
  text-align: center;
}

.title {
  color: var(--light-grey);
  margin: 20px 0;
}

#author-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.user-card {
  border-radius: 15px;
  width: 300px;
  height: 350px;
  background-color: var(--light-grey);
  margin: 20px;
}

.user-img {
  width: 150px;
  height: 150px;
  object-fit: cover;
}

.purple-divider {
  background-color: var(--dark-purple);
  width: 100%;
  height: 15px;
}

.author-name {
  margin: 10px;
}

.bio {
  margin: 20px;
}

.error-msg {
  color: var(--light-grey);
}

.btn {
  cursor: pointer;
  width: 200px;
  margin: 10px;
  color: var(--main-bg-color);
  font-size: 14px;
  background-color: var(--golden-yellow);
  background-image: linear-gradient(#fecc4c, #ffac33);
  border-color: var(--golden-yellow);
  border-width: 3px;
}
/* file: script.js */
const authorContainer = document.getElementById('author-container');
const loadMoreBtn = document.getElementById('load-more-btn');


// User Editable Region

let startingIndex = 0;
function displayAuthors(authors) {
  authorContainer.innerHTML = ""; // Clear previous authors

  for (const author of authors) { // Declare 'author' using 'const'
    console.log(author); // Debugging: Log the author object

    authorContainer.innerHTML += `
      <div class="user-card">
        <h2 class="author-name">${author.name}</h2> 
      </div>
    `;
  }
}



// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build an fCC Authors Page - Step 8

Welcome to the forum :wave:

It looks like you’re missing a bunch of code at the beginning

It might be a good idea to reset this step if that code is missing, or maybe it didn’t get put into this thread.

Next:

The card should have the following structure:
Example Code

<div id="${index}" class="user-card">
  <h2 class="author-name">${author}</h2>
</div>

You are given this structure for the div in the instructions, you are missing the index number.

Next, look at your console.log output:

[ { author: 'Quincy Larson',
    image: 'https://www.freecodecamp.org/news/content/images/size/w150/2021/03/Quincy-Larson-photo.jpg',
    url: 'https://www.freecodecamp.org/news/author/quincylarson/',
    bio: 'The teacher who founded freeCodeCamp.org.' },

Note the structure of the authors objects. Note the names of each key. What key will you use to access the author’s name?

You are very close!