Tell us what’s happening:
This passes all of the tests except: urlSlug(" Winter Is Coming") should return “winter-is-coming”.
Note that there is two spaces between Is and Coming in the input string above.
I added the + sign to my regular expression in the split method to account for this additional space, and when I enter the code as it is in repl.it > javascript it returns “winter-is-coming”. Thus, it seems to me that the code should pass all the tests on freeCodeCamp, but it doesn’t pass the one I’ve noted.
Please, help. Thanks!
Edit: Of course, the function can be reduced to the single line return title.toLowerCase().split(/\W+/).join('-');
. I have it separated for bug control and clarity as I’m learning.
Your code so far
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
var little = title.toLowerCase();
var arr = little.split(/\W+/);
var strAct = arr.join('-');
return strAct;
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs