What I am really missing?

Tell us what’s happening:

Not working for the last two test cases.
What I am doing wrong?

   **Your code so far**

// greatest common divisor
function gcd(a, b){
 if(a < b){
   [a, b] = [b, a]
 }
 if(a % b === 0){
   return b;
 }
 else{
   return gcd(a, a%b);
 }
}

//  find lcm of two numbers
function lcm(a , b){
 return (a * b) / gcd(a, b);
}

// main function
function smallestCommons(arr) {
// get starting number and ending number
let min = Math.min(arr[0], arr[1]);
let max = Math.max(arr[0], arr[1]);
let multiple = max;

for(let i = min; i < max; i++){
  multiple = lcm(multiple, i);
}

console.log(multiple);
return multiple;  
}

smallestCommons([1,5]);
smallestCommons([1, 13]);   
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.

Challenge: Smallest Common Multiple

Link to the challenge:

The mistake is in your gcd function, you can see that if you
console.log(gcd(300,175)) (should be 25, but your function returns 50).

It’s just one wrong character in the return statement.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.