Hello I’m triying to solve this problem. I think I got it but the answer checker throws the next message to me:
The globalTitle variable should not change.
But in fact I’m not changing the original string because in the function I copy the string into another variable with concat method. So the alert throwed by freeCodeCamp has no sense.
Your code so far
// the global variable
var globalTitle = " Winter Is Coming";
console.log(globalTitle);
// Add your code below this line
function urlSlug(title) {
let url = title.concat("")
return url.split(/\s+/).filter(a => "" !== a).join("-").toLowerCase();
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
console.log(winterComing);
console.log(globalTitle);
THE ANSWER: The problem was that I changed the input variable to check when the input is " Winter Is Coming" then freeCodeCamp is not truly checking that the input variable is the same after the code execution instead they stored the variable with the value of “Winter Is Coming” and the background code of the challenge limits to check if the globalTitle matches with that string after de execution.
And that is a bug.
To be fair, if the tests have to account for any possible unknown change then it isn’t possible to write tests: the tests have to assume that you haven’t changed the code that you aren’t supposed to change.
Ok is only for curiosity. Also I’ve found that many code examples don’t use arrow functions with methods, for example, which is very well suited scenario to use arrow functions (taking in account that freeCodeCamp should be ES6 compilant)