Apply Functional Programming to Convert Strings to URL _slugs

Tell us what’s happening:
My code passes all the tests except one: “the globalTitle variable should not change.” I’m having trouble understanding why this one test fails; It works perfectely in my console but it doesn’t work on FCC. Isn’t a string passed by value to a function or is that wrong? I’ve tried creating a local copy of the string and that failed on FCC as well. Can someone please explain this to me? Thanks and I would appreciate the help.

Your code so far


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

// Add your code below this line
function urlSlug(title) {
  return title.trim().split(/\s+/).join('-').toLowerCase();
}
// 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/67.0.3396.79 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

Code looks good to me. Try a hard refresh of the browser and submit again.

Hopefully that helps :slight_smile:

Hi @azhang213

It looks like at some point you’ve added some spaces to the globalTitle variable because it should like like this:

// Default:
var globalTitle = "Winter Is Coming";

// Your's
var globalTitle = " Winter Is  Coming";

You have a space at the beginning and an extra space between Is and Coming. Remove the extra spaces and try again.