Problem in Convert Strings to URL Slugs

Problem in Convert Strings to URL Slugs
0
#1

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?

#2

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

#3

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
#4

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