Misleading error log

I just spent an hour trying to debug my code solution for the following lesson: JavaScript Basic Algorithm Scripting → Confirm the Ending.

I was pretty confident in my code (pasted at the bottom), however all the tests would fail in the sidebar

Furthermore, FreeCodeCamp’s built-in logs were also telling me that my code is being ran, and producing incorrect results for all tests like so:

I only found out the root of the issue when I was refactoring my entire code: as soon as I deleted the last line in my code that was trying to log a variable to the console that wasn’t declared, the test passed.

After ~30 google tabs looking into this and thinking about it I recognized that the FreeCodeCamp editor most likely returned all fail results because during tests it appends the test function calls below the script. It ran into a ReferenceError before being able to call the test functions, therefore I’m guessing it was unable to run it even once, hence the all fail result. However, in my case (and I imagine I’m not the only one) when I submitted my code, I received incomplete and therefore misleading information, that only introduced confusion due to the non-user friendly way it was presented.

I thought the problem was not just the ReferenceError, but also my solution being fundamentally incorrect, as the log and the check/error marks in the nav bar indicated a fail for every passing criteria. This was made worse because the logs were telling me it was “running tests” and “tests completed”, even though that wasn’t the case.

My suggestion would be to reduce ambiguity by communicating to the user that their code wasn’t ran a single time due to an error and that’s why it returned incorrect test results, as opposed to telling the user they failed all tests. While technically true, I believe it would be helpful to use the same warning function as when you try to run a script with an infinite loop:

“Potential infinite loop detected on line 1. Tests may fail if this is not changed.”

This would similarly let the user know their script will (almost?) certainly fail due to this critical error on line X, and they should run the script with that in mind.

I’m not sure if this is the right place to post this as it’s more of a general issue/suggestion as opposed being directly related to the lesson, this is my first forum post so apologies if it isn’t.

Please let me know what you think!

My code, note the last line that was the root of the issue

function confirmEnding(str,target) {
  const charsArray = str.split(""); //convert string to array
  const charsToCheckArray = []; //empty array that for statement populates

  //populate charsToCheckArray var with (str)'s last (target.length) characters 
  for (let i = - 1; Math.abs(i) <= target.length; i--){
    charsToCheckArray.unshift(charsArray.slice(i)[0]);
  }
  //convert array to string
  const charsToCheckString = charsToCheckArray.join("");

  //returns solution to challenge (boolean)
  if (charsToCheckString == target){
    return true;
  }
return false;
}

console.log(confirmEnding("Bastian", "n"));
console.log(confirmEnding("Congratulation", "on"));
console.log(confirmEnding("Connor", "n"));
console.log(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification"));
console.log(confirmEnding("He has to give me a new name", "name"));
console.log(confirmEnding("Open sesame", "same"));
console.log(confirmEnding("Open sesame", "sage"));
console.log(confirmEnding("Open sesame", "game"));
console.log(confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain"));
console.log(confirmEnding("Abstraction", "action"));



console.log(undeclaredVariableForTestingPurposes);

You can’t just ignore a reference error and expect the program to still work, it is an exception and must be corrected.

The check for infinite loops is not an error. JS doesn’t really care if you create an infinite loop. The runtime might, for example, the browser letting the user know a script is running for longer than expected. JS can’t catch an infinite loop, technically nothing can, as proving something is infinite is impossible. You can guesstimate it based on how long it is running and if that is longer than “expected”.

The fCC compiler rejecting a solution for having a reference error in it is not the issue, I didn’t imply it was or anything like that.

My main point is the following, regarding fCC compiler logs (that are supposed to help you, lead you into the right direction by displaying educational info that other compilers don’t) being misleading:

I thought the problem was not just the ReferenceError, but also my solution being fundamentally incorrect, as the log and the check/error marks in the nav bar indicated a fail for every passing criteria. This was made worse because the logs were telling me it was “running tests” and “tests completed”, even though that wasn’t the case.

About your second paragraph, I appreciate the detail, but again my main point of criticism/suggestion has nothing to do with JS or how the code behaves under different circumstances. I do realize the check for infinite loops is not an error, that’s why I called it a function of the compiler. It’s a user-friendly nudge in the right direction from the compiler.

I believe it would be helpful to use the same warning function as when you try to run a script with an infinite loop:
“Potential infinite loop detected on line 1. Tests may fail if this is not changed.”

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.