Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs : Global Varible error

Couldn’t pass test case:- **The globalTitle variable should not change.

In my code below I have check globalTitle variable is not changing at any stage, please help!

Question Link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs

// The global variable
const globalTitle =" Winter Is  Coming";

console.log(urlSlug(globalTitle));

// Only change code below this line
function urlSlug(title) {
var t2=title;
t2= t2.toLowerCase();

 t2=t2.split((/\s+/))
//console.log(t2);

//console.log(t2.join('='));
var r=t2.join('-');

//console.log(globalTitle);
if(r[0]=='-')
{return r.slice(1,r.length);}
else{

  return r;

}
}
// Only change code above this line

Hello there,

I have moved this post to a more suitable sub-forum.

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

To answer your question:

Your globalTitle has been changed. Copy the code you want to keep, then reset the challenge.

Hope this helps

Thanks for moving the post!

How globalTitle has been changed?

What it is supposed to be:

var globalTitle = "Winter Is Coming";
1 Like

when there is a line like this, and you do not respect it, you could fail tests for that reason

next time you can test by creating a new function call…

1 Like

Thanks @ilenia and @Sky020