Convert Strings to URL Slugs Global Variable

Hi all,

I’ve managed to complete this challenge except for the fact that I’m failing the “The globalTitle variable should not change.” I’m scratching my head here. What part of my code is changing the global variable?

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

// Add your code below this line
function urlSlug(title) {
  let slug = title.slice();
  return slug.toLowerCase().split(/\W/).filter((item) => item.length > 0).join("-");
// Add your code above this line

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

Thanks in advance!

Link to challenge:

Check the link below!

1 Like

Nothing in your code modifies argument to me, even if you would have removed .slice() line completely and return title.... you still wouldn’t change it.

Two notes:

  1. You might want /\W+/ just in case there are more then one non-word character
  2. You might want to trim() argument as well :wink:
1 Like

Thanks, worked like a charm! That /\W+/ let me get rid of that filter method.