Convert Strings to URL Slugs0

Tell us what’s happening:
Only this below one test case fails, please help me out. thanks in advance
urlSlug(" Winter Is Coming") should return "winter-is-coming" .

Your code so far

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

// Add your code below this line
function urlSlug(title) {
  var t = title.toLowerCase().split(' ').join('-');
  return t;
// Add your code above this line

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.

Link to the challenge:

You should try to use debugging tool, like copying your code in the browser console, or using console.log() statements

Considering that that string has a space at the beginning, the result is -winter-is-coming

The first element of your array after you split the string is an empty string. Think of how you can get rid of it using built-in array methods.

yeah, i solved it by applying trim(), it solves only spaces before and after the string. But, how to solve with more spaces in between the string??

Use regex inside split. Something like this:


It matches one or more spaces.