## Intermediate Algorithm Scripting: Smallest Common Multiple

Greetings,

I’ve been trying to solve this challenge independently for a few hours now, and I’ve pretty-much found my solution. However, for some reason the code stops functioning when one of the given arguments is 23 or higher (as in the last criteria for the challenge). When given these arguments, it returns undefined. My guess is that it could be to do with the code looping too many times, as it’s a rather clunky solution. But I don’t know for sure, so any clarity would be much appreciated.

Thank you

**My code so far**

```
function smallestCommons(arr) {
// sort array and calculate range of numbers
arr.sort((a, b) => a - b);
let rangeArr = [];
for (let i = arr[0]; i <= arr[1]; i++) {
rangeArr.push(i);
}
// calculate Least Common Multiple
let LCM = arr[1];
while (LCM % arr[0] !== 0) {
LCM += arr[1];
}
let counter = 0;
while (counter !== rangeArr.length){
for (let j = 0; j < rangeArr.length; j++) {
if (LCM % rangeArr[j] === 0) {
counter++;
}
}
if (counter == rangeArr.length) {
return LCM;
}
else {
LCM += arr[1];
counter = 0;
}
}
}
console.log(smallestCommons([1,13]));
```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36`

.