# Smallest Common Multiple maybe a bug?

Smallest Common Multiple maybe a bug?
0

#1

Hi,

I think I solved this exercise but the last condition is still unchecked.

I used the console to check what it was being returned, and it returns the same as the requirement. So I am confused whether it’s a bug or am I missing something?

These are the screenshots:

This is my code:

``````function smallestCommons(arr) {
if (arr[0] < arr[1]){
var a = arr[0];
var b = arr[1];
} else{
var a = arr[1];
var b = arr[0];
}
var commonMultiple = 0;
for (var i = 1; commonMultiple === 0; i++){
if( i % a === 0 && i % b === 0){
commonMultiple = i;
for (var j = a + 1; j < b; j++){
if(commonMultiple % j != 0){
commonMultiple = 0;
j = b;
}
}
}
}
return commonMultiple;
}

smallestCommons([1,5]);
``````

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple

#2

That usually means that the exercise has timed out, that your code isn’t efficient enough.

Yes, the test fail message should be better.

#3

Then I have to find another way to make it “shorter” and “faster” to pass it?

#4

Faster, yes, more efficient.

This is a common difficulty that people have on this challenge. Yes, there are brute force ways to solve it, but there are also more efficient ways.