Apply Functional Programming to Convert Strings to URL Slugs-Latest

Tell us what’s happening:
Hello everyone, I am getting all the tests passed but the one where the title argument is “urlSlug(” Winter Is Coming") should return “winter-is-coming”."

My current code returns “-winter-is-coming”. I am off by the first hyphen in my return statement.

Any suggestions would be appreciated.


Your code so far

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

// Add your code below this line
function urlSlug(title) {
  let lowerCase = title.toLowerCase();
  let array = lowerCase.split(/\s+/gi);
  let url = array.join("-");
  return url;
// Add your code above this line

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

Your browser information:

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

Link to the challenge:

how about using trim() on your string before you do the hyphenation?


I used trim before I performed the join method. That passed the test

Yaaay! I got tripped up by that one too. :wink: