Problem in Convert Strings to URL Slugs

I am in the functional programming chapter in JavaScript.So, I need to convert a string into url Slugs.
this is my code:

function urlSlug(title) {
   return title.trim().toLowerCase().split(/\s/).join("-");

well I need to convert

var globalTitle = "Winter Is Coming";

and result would be  "winter-is-coming"

So I my result is same. My code is working but why freecodecamp show wrong. Please someone tell is there a problem in my code?

Your string converts “Winter Is Coming” fine.

It doesn’t convert: " Winter Is    Coming" <–edited to show whitespace properly. You need to add a check for multiple spaces within the string before doing the ‘space-to-dash’ conversion.

Thanks for the heads-up @kerafyrm02

It does convert " Winter Is Coming".

It seems FCC removes double spaces in any given string.

But the part you need to check for is “Winter[space]Is[space][space]Coming”.

1 Like

Ok now I understand I just need to add split(/\s+/) so it can select all white spaces together