# Smallest Common Multiple - last criteria

**URL:** <https://forum.freecodecamp.org/t/smallest-common-multiple-last-criteria/154180>\
**Category:** General\
**Created:** [October 20, 2017, 2:38pm UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-last-criteria/154180 "2017-10-20T14:38:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laddeyboy](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@laddeyboy](https://forum.freecodecamp.org/u/laddeyboy)\
**Post date:** [October 20, 2017, 2:38pm UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-last-criteria/154180/1 "2017-10-20T14:38:24Z")

</div>

Ok, so the below code works for all test criteria but the last one, when I run the test on fcc, it fails the call to array points [23,18]. BUT…if I put my code into a jfiddle, the number matches actually to the expected test result. So how can my code work in a jsfiddle, but not fcc?? Here’s my code (and yes not elegant, but I’ve been on this challenge for a while and just wanted a working solution.)

```auto
function numRangeArray(start, end){
  var myArr = [];
  for(var i = start; i >= end; i--){
    myArr.push(i);
  }
  return myArr;
}

function smallestCommons(arr) {
  if(arr[0] > arr[1]) {arr = numRangeArray(arr[0], arr[1]);}
  else {arr = numRangeArray(arr[1], arr[0]);}
  //arr is not sorted high to low with all numbers in range
  
  var smallestCommonMultiple = 0;
  var index= 1;
  while(smallestCommonMultiple === 0){
    var temp = arr[0] * index;
    var counter = 0;
    for(var j = 0; j < arr.length; j++){
    	if(temp % arr[j] === 0){
      	counter++;
      } else if(temp % arr[j] !== 0){
      	break;
      }
     }
     if(counter === arr.length){
     	smallestCommonMultiple = temp;
     } else {
     	index++;
     }
    }
    console.log("Smallest: " + smallestCommonMultiple);
  return smallestCommonMultiple;
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:37pm UTC](https://forum.freecodecamp.org/t/smallest-common-multiple-last-criteria/154180/3 "2021-01-17T20:37:04Z")

</div>

Closed on January 17, 2021, 8:37pm UTC


