Smallest Common Multiple failed test case

Following test fails on the site but runs correctly on my machine:
smallestCommons([23, 18]) should return 6056820.

Your code so far

  var smallestMultiple, small, large;
  if(arr[0] < arr[1]) {
    small = arr[0];
    large = arr[1];
  } else if(arr[0] > arr[1]) {
    small = arr[1];
    large = arr[0];
  } else {
    return arr[0];
  if(large - small == 1) return lcm(small, large);
  smallestMultiple = lcm(small, small+1);

  for(var i = small+2; i <= large; i++){
    smallestMultiple = lcm(smallestMultiple, i);
  return smallestMultiple;

function lcm(n1, n2) {
  minMultiple = (n1>n2) ? n1 : n2;
  // Always true
  while(1) {
    if( minMultiple%n1==0 && minMultiple%n2==0 ) {
  return minMultiple;


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:

It looks like you left off the first bit of your code. My guess is that it’s probably timing out. FCC uses infinite loop protection to stop you from crashing your browser. Even if your code doesn’t generate an infinite loop, the protection will kick in if it takes too long to run.

1 Like