JavaScript tests in challenges no longer working correctly

I recently completed the “No repeats please challenge” with this code:

And it worked just fine. But later, I was trying to demonstrate the code to someone, and everytime I would try to run the tests, I would get this message in the tests log on the side:

Error: SyntaxError: Unsafe or unfinished function declaration

Here is what the JavaScript console in Firefox Nightly showed:

I tried using Chromium instead, but the issue persisted. Here is what was shown in the Chromium JavaScript console:

I tried the code on CodePen, and it worked just fine there. As I looked into the issue some more, I discovered that any function defined like so would cause an issue: const funcName = () => {}; That was weird, because I had done many challenges before, all of which used functions defined like that.

I then tried this simple piece of code:

When I ran the tests, this error appeared in the JavaScript console in Chromium:

Using var instead of let made the error not appear in the console. When testing this piece of code in Firefox Nightly, no errors appeared in the JavaScript console, but instead the tests log on the side got stuck showing this message:

// testing challenge…

But this was not happening a couple days ago. let and const would both work just fine, as would basically any newer JavaScript feature.

It seems like something has changed in the backend code of freeCodeCamp that has introduced some bugs or something, because now a lot of code that was working (and works just fine on other sites) is no longer passing the tests.

Does anyone have any idea what has gone wrong?

I’m guessing that you added comments when you decided to demonstrate you code. It looks like there is a flaw in the safe code detection. It is seeing the word “function” in your comments and identifying it as a malformed function declaration.

window.common = function(e) {
    var n = e.Rx.Observable
      , t = e.common
      , o = void 0 === t ? {
        init: []
    } : t
      , r = /function\s*?\(|function\s+\w+\s*?\(/gi // this is causing an error when the word 'function' is used in a comment
      , i = /\$\s*?\(\s*?\$\s*?\)/gi
      , a = /if\s\(null\)\sconsole\.log\(1\);/gi;
    return o.detectUnsafeCode$ = function(e) {
        var t = e.match(/\/\*/gi)
          , o = e.match(/\*\//gi);
        return t && (!o || t.length > o.length) ? n["throw"](new Error("SyntaxError: Unfinished multi-line comment")) : e.match(i) ? n["throw"](new Error("Unsafe $($)")) : e.match(/function/g) && !e.match(r) ? n["throw"](new Error("SyntaxError: Unsafe or unfinished function declaration")) : e.match(a) ? n["throw"](new Error("Invalid if (null) console.log(1); detected")) : n.just(e)

Would you mind creating a GitHub Issue to log this bug you found?

FYI: Your code still won't pass the tests if you remove the word 'function' from the comments, but I suspect that is because the length of time required to execute some of the test cases is triggering the infinite loop protection.

I just removed all the instances of “function” in the comments, and my code was able to pass the test! I guess nothing actually changed in freeCodeCamp… it was just that I added a bunch of comments after finally getting the code to work, just like you guessed. I would have never thought that those would be the cause of the issue! Thank you!

I took a look on the GitHub project and it looks like this issue has already been reported:

Hopefully it gets fixed soon! Again, thanks for figuring out the issue… I probably would have gone on for multiple days trying to figure it out myself. :smile:

1 Like