curriculum/challenges/english/blocks/learn-fetch-and-promises-by-building-an-fcc-authors-page/641da97c987a514959ada414.md
Now call the displayAuthors function with a portion of the author data just like you did before.
If you click the Load More Authors button after calling the function, it won't work. That's because you still have to add the click event listener to the button. You'll do that next.
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
You should call your displayAuthors function.
const afterAdd = code.split("endingIndex += 8;")[1];
assert.match(afterAdd, /displayAuthors\(/)
You should call your displayAuthors function and pass in an argument of authorDataArr.slice().
const afterAdd = code.split("endingIndex += 8;")[1];
assert.match(afterAdd, /displayAuthors\(\s*authorDataArr\.slice\(/)
The first argument of your slice() method should be startingIndex.
const afterAdd = code.split("endingIndex += 8;")[1];
assert.match(afterAdd, /displayAuthors\(\s*authorDataArr\.slice\(\s*startingIndex/)
The second argument of your slice() method should be endingIndex.
const afterAdd = code.split("endingIndex += 8;")[1];
assert.match(afterAdd, /displayAuthors\(\s*authorDataArr\.slice\(\s*startingIndex\s*,\s*endingIndex\s*\)\s*\)/)
<!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>
* {
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;
}
const authorContainer = document.getElementById('author-container');
const loadMoreBtn = document.getElementById('load-more-btn');
let startingIndex = 0;
let endingIndex = 8;
let authorDataArr = [];
fetch('https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json')
.then((res) => res.json())
.then((data) => {
authorDataArr = data;
displayAuthors(authorDataArr.slice(startingIndex, endingIndex));
})
.catch((err) => {
console.error(`There was an error: ${err}`);
});
const fetchMoreAuthors = () => {
startingIndex += 8;
endingIndex += 8;
--fcc-editable-region--
--fcc-editable-region--
};
const displayAuthors = (authors) => {
authors.forEach(({ author, image, url, bio }, index) => {
authorContainer.innerHTML += `
<div id="${index}" class="user-card">
<h2 class="author-name">${author}</h2>
<p class="bio">${bio}</p>
<a class="author-link" href="${url}" target="_blank">${author}'s author page</a>
</div>
`;
});
};