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;
   }
   else{
       min = lastEl;
       max = firstEl;
  } 

  let divNum = max;
    
   for( let i = min; i <= max; i++ ){
        count++;
        newArr.push(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;
                j++;
            } 
   }
   
 
   let endScm = getScm(divNum);
      console.log(endScm)
   return endScm; 


}


smallestCommons([23,18]);

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

The code works, tested on the jsconsole.com. 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 https://jsbin.com/ 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.

http://forum.freecodecamp.org/t/free-code-camp-infinite-loop-protection/19550