Tell us what’s happening:
i keep failling the 32. test on build an fcc forum leaderboard where The first td element of each table row from the string returned by showLatestPosts should contain two anchor elements, the first with the class of post-title, an href of /, an anchor text of , and the second obtained by calling forumCategory with category_id.
and its still failing
Your code so far
const forumLatest = 'https://cdn.freecodecamp.org/curriculum/forum-latest/latest.json';
const forumTopicUrl = 'https://forum.freecodecamp.org/t/';
const forumCategoryUrl = 'https://forum.freecodecamp.org/c';
const avatarUrl = 'https://forum.freecodecamp.org';
const allCategories = {
299: { key: 'Career Advice', className: 'career' },
200: { key: 'General', className: 'general' },
500: { key: 'Showcase', className: 'showcase' },
409: { key: 'Project Feedback', className: 'feedback' }
};
/* ======================
TIME AGO
====================== */
function timeAgo(timestamp) {
const now = new Date();
const then = new Date(timestamp);
const diffMs = now - then;
const minutes = Math.floor(diffMs / 60000);
if (minutes < 60) return `${minutes}m ago`;
const hours = Math.floor(minutes / 60);
if (hours < 24) return `${hours}h ago`;
const days = Math.floor(hours / 24);
return `${days}d ago`;
}
/* ======================
VIEW COUNT
====================== */
function viewCount(views) {
return views >= 1000 ? `${Math.floor(views / 1000)}k` : views;
}
/* ======================
FORUM CATEGORY
====================== */
function forumCategory(id) {
const category = allCategories[id] || { key: 'General', className: 'general' };
return `<a href="${forumCategoryUrl}/${category.className}/${id}" class="category ${category.className}">${category.key}</a>`;
}
/* ======================
AVATARS
====================== */
function avatars(posters, users) {
return posters.map(poster => {
const user = users.find(u => u.id === poster.user_id);
if (!user) return '';
let src = user.avatar_template.replace('{size}', '30');
if (!src.startsWith('http')) {
src = 'https://cdn.freecodecamp.org/curriculum/forum-latest' + src;
}
return `<img src="${src}" alt="${user.name}">`;
}).join('');
}
/* ======================
SHOW LATEST POSTS
====================== */
function showLatestPosts(data) {
const { users, topic_list } = data;
const rows = topic_list.topics.map(topic => {
const { id, title, views, posts_count, slug, posters, category_id, bumped_at } = topic;
// First <td> must contain two anchors exactly: post-title + category, separated by a single space
return `<tr>
<td><a class="post-title" target="_blank" href="${forumTopicUrl}${slug}/${id}">${title}</a> ${forumCategory(category_id)}</td>
<td><div class="avatar-container">${avatars(posters, users)}</div></td>
<td>${posts_count - 1}</td>
<td>${viewCount(views)}</td>
<td>${timeAgo(bumped_at)}</td>
</tr>`;
}).join('');
document.getElementById('posts-container').innerHTML = rows;
}
/* ======================
FETCH DATA
====================== */
async function fetchData() {
try {
const res = await fetch(forumLatest);
const data = await res.json();
showLatestPosts(data);
} catch (err) {
console.log(err);
}
}
fetchData();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 OPR/125.0.0.0
Challenge Information:
Build an fCC Forum Leaderboard - Build an fCC Forum Leaderboard
