Question about a Javascript Exercise

I am working on the exercise at https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs and my code for the function is:

function urlSlug(title) {

let retStr = title.toLowerCase().split(/\W/).join("-");

return retStr;

}
This code passes all of the tests but one. It fails the test ‘urlSlug(" Winter Is Coming") should return “winter-is-coming”’. I have tested the code and it seems to return the desired string. Why is this code failing this one test?

Does adding this line at the bottom help you see what’s going on?

console.log(urlSlug(" Winter Is Coming"))

That’s how I tested it. That line returns “winter-is-coming” which the failed test says I should get.

Does it?

1 Like

I see what you are talking about. I was testing the wrong version of that string. Thanks

1 Like