Apply Functional Programming to Convert Strings to URL Slugs - Console results are good, but it doesn't pass me

Tell us what’s happening:
Can’t understand why my code is not working. Everything seems ok in the console when I run it. Tried to do it in different ways, but keep getting the same issue:
http://take.ms/e3lhk

When looking for help I saw some people using map, filter or reduce methods and seem to have no issues. I don’t want to simply copy it :confused: I don’t understand why it seems necessary to use those methods if my results on the console seem correct.

Any help plz?

Your code so far


// the global variable
var globalTitle = "Winter Is Coming";

// Add your code below this line
function urlSlug(title) {
  console.log(
      title.trim()
        .toLowerCase()
        .split(/\W+/)
        .join('-')
  );
  return
      title.trim()
        .toLowerCase()
        .split(/\W+/)
        .join('-');  
}
// 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_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 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/

your function returns undefined at the moment
(simply add console.log for winterComing variable and you will see that)

Let us know if you need further help identifying why it is giving undefined…

Thank you guys :smile: I haven’t realized that. Feeling stupid as usual after asking for something obvious. That’s quite typical for me :blush: