Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs - my solution

My solution to this challange:

// the global variable

var globalTitle = "Winter Is Coming";

// Add your code below this line

function urlSlug(title) {

return globalTitle.split(" ").map(val =>; val.toLowerCase()).join("-");


// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"

Can anybody tell me what is wrong with my code? I’ve tested it in the Chrome’s console and it works just fine.

First of all, your function should be referencing the argument passed into your function and not the global variable globalTitle.

After resolving that, you will find your function is only failing the 4th test. Why? Because, your function returns -winter-is--coming instead of -winter-is–coming` for the 4th test.

1 Like

Hey! Thanks for helping me out. I haven’t spotted that - it’s my silly mistake.

Now, my adjusted and working solution is:

function urlSlug(title) {

return title.split(" ").map(val => val.toLowerCase()).filter(val =>

val.length > 0).join("-");


Thanks again! Cheers!