Convert Strings to URL Slugs what is wrong with my code?

Tell us what’s happening:

Hello
nearly 1.5 hour I’m trying to catch what is wrong with my code
the last test which I cant to get is
The globalTitle variable should not change.
dose it mean that my code changing the global variable and return not a copy?

Your code so far


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

// Add your code below this line
function urlSlug(title) {   
  let str =  ''.concat(title)
  .split(/\W/)
  .filter(a =>  a !== '')
  .join("-")
  .toLowerCase(); 
  return str;
}

// Add your code above this line
 
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
console.log(winterComing)
console.log(globalTitle)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 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

You are not suppose to update that variable because of it you may getting error.

var globalTitle = "Winter Is Coming";

// Add your code below this line
function urlSlug(title) {
  return title.toLowerCase().trim().split(/\s+/).join('-');
}
// Add your code above this line

var winterComing = urlSlug(globalTitle);

This code Exactly works for me …
Go through it you may have some idea

Maybe I’m so stupid but yours code don’t working for me :rofl:


Even now i cleared all test case man

Clear Cache try to do with other browser sometime it happen and i don’t know why
hope it helps you

You need the globalTitle to be as it was in the original code - remove the space at the beginning

1 Like

I have try this solution from hints

function urlSlug(title) {   
  return title
  .split(/\W/)
  .filter(a =>  a !== '')
  .join("-")
  .toLowerCase(); 
 
}

I have try this solution

function urlSlug(title) {
  return title
  .toLowerCase()
  .trim()
  .split(/\s+/)
  .join('-');
}

nothing :joy_cat:

Because you don’t read the hints:

REMOVE the space in globalTitle before the W.

2 Likes

Thanks
I’m rely stupid :joy:

1 Like