Can't pass Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs

Tell us what’s happening:
I don’t know why urlSlug(" Winter Is Coming") didn’t pass

should return

"winter-is-coming"

.

Your code so far


// The global variable
var globalTitle = "Winter Is Coming";

// Only change code below this line
function urlSlug(title) {
return title.trim().toLowerCase().split(' ').join('-');
}
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

There are two spaces between “is” and “coming” in the test you are failing. Your split is only looking for one. You either need a different approach, or you need to get your split to remove one or more spaces. Regex would be one way to do that.

1 Like