FreeCodeCamp console calculations

Tell us what’s happening:
Hey guys, my script can’t pass only the last test. Actually, the console calculations stop in a specific number. Any help would be greatly appreciated. Thanks!

Your code so far

function smallestCommons(arr) {
   let firstEl = arr[0];
   let lastEl = arr[arr.length - 1 ];
   let min = 0;
   let max = 0;
   let newArr = [];
   let count = 0;
   let lastScm = 0;

   if(firstEl < lastEl ){
       min = firstEl;
       max = lastEl;
       min = lastEl;
       max = firstEl;

  let divNum = max;
   for( let i = min; i <= max; i++ ){

   function divCm(divNum){
              let sum = 0;
              for(let i = min; i <= max; i++){
                if(divNum % i == 0){
                  sum += 1;
              return sum;

   function getScm(divNum){  
            let j = 2;
              while(lastScm !== count){
                lastScm = divCm(divNum);
                if(lastScm === count){
                  return divNum;
                divNum = max*j;
   let endScm = getScm(divNum);
   return endScm; 



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:

The code works, tested on the So, is it a bug?

Hi Dimis, same problem… my algorithm worked until I got to the higher numbers then it quit. Running it on it had the same problem but told me that it quit early on the higher numbers because it was preventing a potential infinite loop. I wonder if the FCC environment has the same check.

It looks like FCC protects infinite loops by breaking then after 500ms has passed. You can try to put a comment //noprotect to disable this.