Apply Functional Programming to Convert Strings to URL Slugs

Hey guys,
I was just wondering why my code ain’t working, because I got the exact result in VScode as is mentioned below // running tests (link here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs).
My code:

// Only change code below this line
function urlSlug(title) {
    let newVar = title.trim().toLowerCase();
    let newArr = newVar.split(" ").join("-");
    return newArr;
}
// Only change code above this line

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

Any help would be appreciated :smiley:

I’ve Checked your code. it seems to work properly
I’ll suggest that you refresh your page and try again. Sometimes these things happen.
Otherwise, you could console.log() other examples. See if all the outputs are correct. Perhaps you can move forward from there

Your code is failing this test:

urlSlug(" Winter Is Coming") should return the string winter-is-coming .

Though it’s not obvious, there are two spaces between ‘Is’ and ‘Coming’ in the above example.

Your code will return a string with two hyphens between ‘Is’ and ‘Coming’. Copy and paste the example test into your console.log to see.

So your code needs to account for any additional internal spaces which are present.

Wow, I didn’t think about that one. Kudos to you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.