Tell us what’s happening:
hello, I’m trying to pass the challenge and only one pass is refusing to go through. But I see no problem in the solution.
**Your code so far**
// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.split(/\W/i)
.join("-");
};
// Only change code above this
console.log(urlSlug("Winter Is Coming"));
console.log(urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone"));
console.log(urlSlug("Hold The Door"));
console.log(urlSlug(" Winter Is Coming"));
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
use the output “Run the Tests” gives you. In your case it doesnt pass for urlSlug(" Winter Is Coming") . Use your solution and print out what your function returns. Its -winter-is-coming. You have an additional hyphen in front of the text. If you check what each of the methods you use in your function returns, you will notice how your split() method handles white space in the beginning of a sentence. It returns an additional empty string, in the array, which you then proceed to concatenate with a hyphen. In order to fix that, you should think of a way to properly handle white spaces in the beginning or an end of a string.