Build an fCC Forum Leaderboard - Build an fCC Forum Leaderboard. Step 15 & 18

Tell us what’s happening:

I can’t get past levels 15 and 18, even though my string looks correct. Any ideas why?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
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://cdn.freecodecamp.org/curriculum/forum-latest';

const allCategories = {
  299: { category: 'Career Advice', className: 'career' },
  409: { category: 'Project Feedback', className: 'feedback' },
  417: { category: 'freeCodeCamp Support', className: 'support' },
  421: { category: 'JavaScript', className: 'javascript' },
  423: { category: 'HTML - CSS', className: 'html-css' },
  424: { category: 'Python', className: 'python' },
  432: { category: 'You Can Do This!', className: 'motivation' },
  560: { category: 'Backend Development', className: 'backend' }
};

function timeAgo(isoDate) {
  const now = new Date();
	console.log(now.toISOString());
  const past = new Date(isoDate);
  const diff = Math.floor((now - past) / 1000);
 	console.log(diff);

  if (diff < 3600) {
		const minutes = Math.floor(diff / 60);
    return `${minutes}m ago`;
  } else if (diff < 86400) {
    const hours = Math.floor(diff / 3600);
    return `${hours}h ago`;
  } else {
    const days = Math.floor(diff / 86400);
    return `${days}d ago`;
  }
}

function viewCount(views) {
	if(views >= 1000) {
		const viewsInK = Math.floor(views / 1000);
		console.log(viewsInK)
		return `${viewsInK}k`;
	} else {
		return views;
	}
}

function forumCategory(categoryId) {
    if (categoryId === 200) {
      return `<a class="category general" href="https://forum.freecodecamp.org/c/career/${categoryId}">General</a>`
    }

		if (categoryId in allCategories) {
			//console.log(allCategories[categoryId].category);
			return `<a class="category ${allCategories[categoryId].className}" href="https://forum.freecodecamp.org/c/career/${categoryId}">${allCategories[categoryId].category}</a>`
		}
}

console.log(forumCategory(299))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 YaBrowser/25.8.0.0 Safari/537.36

Challenge Information:

Build an fCC Forum Leaderboard - Build an fCC Forum Leaderboard

test with this one, call console.log(forumCategory(409)), do you get the correct result? what about all the other category numbers?

With console.log(forumCategory(409)) I have this. I think it is correct.

<a class="category feedback" href="https://forum.freecodecamp.org/c/career/409">Project Feedback</a>

no, there is career in the url, that is not correct

I think I get it. But why can’t I pass test 18?
There’s no “general” category in the allCategories object. So I just write:

return `<a class="category general" href="${forumCategoryUrl}general/${categoryId}">General</a>`

can you share the updated code please? I need more than this line

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://cdn.freecodecamp.org/curriculum/forum-latest';

const allCategories = {
  299: { category: 'Career Advice', className: 'career' },
  409: { category: 'Project Feedback', className: 'feedback' },
  417: { category: 'freeCodeCamp Support', className: 'support' },
  421: { category: 'JavaScript', className: 'javascript' },
  423: { category: 'HTML - CSS', className: 'html-css' },
  424: { category: 'Python', className: 'python' },
  432: { category: 'You Can Do This!', className: 'motivation' },
  560: { category: 'Backend Development', className: 'backend' }
};

function timeAgo(isoDate) {
  const now = new Date();
	console.log(now.toISOString());
  const past = new Date(isoDate);
  const diff = Math.floor((now - past) / 1000);
 	console.log(diff);

  if (diff < 3600) {
		const minutes = Math.floor(diff / 60);
    return `${minutes}m ago`;
  } else if (diff < 86400) {
    const hours = Math.floor(diff / 3600);
    return `${hours}h ago`;
  } else {
    const days = Math.floor(diff / 86400);
    return `${days}d ago`;
  }
}

function viewCount(views) {
	if(views >= 1000) {
		const viewsInK = Math.floor(views / 1000);
		console.log(viewsInK)
		return `${viewsInK}k`;
	} else {
		return views;
	}
}

function forumCategory(categoryId) {
    if (categoryId === 200) {
      return `<a class="category general" href="${forumCategoryUrl}general/${categoryId}">General</a>`;
    }

		if (categoryId in allCategories) {
			//console.log(allCategories[categoryId].category);
			return `<a class="category ${allCategories[categoryId].className}" href="${forumCategoryUrl}${allCategories[categoryId].className}/${categoryId}">${allCategories[categoryId].category}</a>`
		}
}

is this the requirement for general? double check that. 200 is what is being tested, but your function should follow the requirements (user story 6 and 7)

1 Like

Thank you! I solved this problem.