What's the catch?

Tell us what’s happening:

It seems like my code contains all the rules of the task, but for some reason the tester does not let me go to the next lesson.

Your code so far

// Only change code below this line
function urlSlug(title) {
return title.toLowerCase().trim().split(/\W/).join("-");


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

Your browser information:

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

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

1 Like

I copied and pasted the failed test, the output is winter-is--coming


I would recommend you use console.log to see what your function is returning each time so you know where the problem is. Then once you figure that out you should be able to tell what needs to be fixed.

Hint: It can be fixed with the addition of one character to the code you already have.


Thanks for the advice, I do just that, I also realized that if I add β€œ+” to the split parameters (/ \W +/), then the exercise is performed. I do not understand why the exercise is not performed without β€œ+”, what exactly this β€œ+” affects, because without it I do not break any rule in the given task

1 Like

try to see what does this gives:

console.log("Hello  World".split(\W+))

(note that there are two spaces in the middle)

1 Like

oh now I understand, thanks to your example, β€œ+” removes all characters including β€œ-” and spaces. Appreciate for support.

A great site for explaining regular expressions is regex101. Type β€œ\W+” in there and it will tell you exactly what the + is doing.

1 Like

Actually, no, + is not removing anything, it is matching things.

1 Like

appreciate for this resource I’ll save it in my notes )