Getting the correct output but its saying incorrect

Tell us what’s happening:
It is saying that this code is not correct. However, when I console log it it seems to be giving the output that it is after. Can someone have a look and let me know what I am doing wrong. I have done the split so that it matches 1+ white spaces

Your code so far


// Only change code below this line
function urlSlug(title) {
return title.split(/\W+/)
  .map(a => a.toLowerCase())
  .join("-")

}
// Only change code above this line
console.log(urlSlug("Winter Is   Coming"))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

You’re close. But what happens when the string starts or ends with a space? The test that’s failing has a leading space.

Can you think of a string method you could use, before the split(), that would remove leading or trailing spaces?

1 Like

ahh yeah ok if I use .trim() before that should fix?

1 Like

Exactly right. Well done.