My passing code getting a fail for tests

I am doing the Javascript Algorithms and Data Structure Certification

When I reached the 'Smallest Common Multiple' lesson, my code that I have tested and shows the correct answers according to the page itself is being reported by the page as failing!

`

smallestCommons([1, 13]) returns 360360 and smallestCommons([23, 18]) returns 6056820.

Would like to get someone to check the page perhaps?

FreeCodeCamp has a protection against infinite loops, if your code takes too much time to execute it is stopped, you are almost surely triggering that one
If you want to check add a console.log() before the return statement (logging what you are returning), and open and clear the browser console before running the tests. You will see in the console what the function returns each time it is called in the tests

I am having the same problem with this challenge. I know my code does not have an infinite loop - when I run it in my terminal with node, it executes to completion and gives me the correct answer. In FCC, it just stops running.

If the issue is about code efficiency, there should be an exceeded maximum call stack error thrown (which I have gotten in other challenges). This challenge is just saying the code is wrong, which is not the case.

The infinite loops protection evaluate how much time a loop is running and if it exceed a certain time it will break the loop, if you have a loop that go on for many many iterations and you don’t get the right result it means it is not completing in that time limit and you need a code that is more efficient and requires less time/steps

@ilenia yes, my code should be more efficient, but FCC should be clear about labeling the issue. It’s inconsistent about how it handles the failure, too - the logs return different results without the code being changed.

The time your code need to execute depends also on server load and things, as such it is always different, and the loop will be at different stages when broken

If you feel it requires changes you can open a GitHub issue to discuss this, after checking that a similar issue doesn’t already exist

1 Like

@ilenia thanks for the info and advice. I came back to it after a few days and got it figured out. One issue was a flaw in my logic that I couldn’t see because the code wasn’t executing that far, but the other thing that I think made a difference was commenting out the console.logs (I had a lot) - I wondered if maybe the console had a max length and was therefore breaking after it hit that length. Do you know if that’s true?