Smallest Common Multiple [23, 18] not working

Tell us what’s happening:

Your code so far

function smallestCommons(arr) {
  let max, min;
  if(arr[0] < arr[1]){
    max = arr[1];
    min = arr[0];
  } else {
    max = arr[0];
    min = arr[1];
  let flag = true;
  let item = max;
    for(let i = min; i < max; i++){
      if(item % i !== 0){
        flag = false;
    if(flag == true){
      return item;
    flag = true;
    item += max;

console.log(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/73.0.3683.103 Safari/537.36.

FreeCodeCamp editor has a infinite loop protection that stop loops that take more than a certain time to avoid your browser freezing

You could choose to leave this as “good enough”, or you could choose to refactor your code so that the loops take less time and you would be able to pass the challenge

1 Like