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?
mcalex
May 15, 2019, 12:54pm
#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
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