I have this bug related to Test No. 14.
The text is correct but the test is not passing for some reason.
I tried with another browser, Firefox, and it didn’t work as well.
Update: When I eliminated the const and added the a tag directly to return the test passed. But I think it’s a bug that needs to be fixed because the output didn’t change.
If the allCategories object does not have the selected category id as its property, category should be indicated as General and className should be indicated as general.
Does your code meet this requirement?
Is your forumCategory function always returning something?
I actually was about to do that but I was talking about the bug that when I added the a tag to a variable and returned the variable, the test algorithm invalidated my code, even though the output is correct and when I removed the variable and returned directly, the test passes
There’s no bug. Finish implementing the user stories and then run the tests. The tests are not designed to validate every bit of code you write. They are designed to test your final code with all user stories implemented.
function forumCategory(catId) {
if (Object.hasOwn(allCategories, catId)) {
const result = `<a class="category ${allCategories[catId].className}" href="${forumCategoryUrl}${allCategories[catId].className}/${catId}">${allCategories[catId].category}</a>`;
return result;
}
}
console.log(forumCategory(299))
If you did this way (the way I did), Test No. 14 forumCategory(299) should return a string containing an anchor element with the text Career Advice. wouldn’t pass.
But if you did this way
function forumCategory(catId) {
if (Object.hasOwn(allCategories, catId)) {
return `<a class="category ${allCategories[catId].className}" href="${forumCategoryUrl}${allCategories[catId].className}/${catId}">${allCategories[catId].category}</a>`
}
}
console.log(forumCategory(299))
The test passes even though the output of both are the same.
How can the tests check anything in that function when it only returns a value if a specific condition is met? The bug is in your code, or lack thereof.