Apply Functional Programming to Convert Strings to URL Slugs maybe freeCode has a bug [SOLVED]

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";

// 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"

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.

Link to the challenge:

UPDATE: I even tried the answer provided by freeCodeCamp and voilá I’ve got the same error.

Yep it looks like it’s bugged to me.


You can’t modify the code outside of the area allowed by the comments. @ArielLeslie has it right.

You added a space at the beginning of globalTitle

Yeah you have reason, but it’s reveal that in some ways freeCodeCamp challenges are sometimes poorly coded.

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.

Luckily FreeCodeCamp is open source, if you think you can write the tests in a better way you can contribute on github and make it better!

1 Like

Interesting. How can I change the code?

Note this isn’t a bug at all; the test has to assume the defined input has not been modified.

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)