Challenge Smallest Common Multiple has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36.
so i tried this solution in my local machine with chrome and firefox and it work fine but when i try it in free code camp i get error with smallestCommons([1, 13]) and smallestCommons([23, 18]) even though the result is correct in my local mechine.
freecodecamp give me this error
Error: Potential infinite loop at line 9. To disable loop protection, write:
// noprotect
as the first line. Beware that if you do have an infinite loop in your code this will crash your browser.
My code:
function smallestCommons(arr) {
var max = Math.max(arr[0],arr[1]);
console.log(max);
var min = Math.min(arr[0],arr[1]);
var answer = 0;
var thereIsAnswer = false;
var num = min;
while(thereIsAnswer===false){
var right = [];
for(var i=min;i<=max;i++){
if(num%i===0){
right.push("R");
}
}
if(right.length===(max-min)+1){
console.log(max-min);
answer=num;
thereIsAnswer=true;
}else{
num++;
}
}
return answer;
}
console.log(smallestCommons([23, 18]));
@mo0kha your code works on freecodecamp; you just need to remove the loop protection per the instructions in the error. Add // noprotect to the first line of the editor and it will pass the challenge.
The loop protect is intended to prevent infinite loops to keep the browser from crashing and sometimes has false-positives.
@mo0kha as @dhcodes has pointed out, if you add the // noprotect to your code, you pass the challenge. Closing this issue as is appears to be resolved. Happy coding!
Most helpful comment
@mo0kha your code works on freecodecamp; you just need to remove the loop protection per the instructions in the error. Add
// noprotectto the first line of the editor and it will pass the challenge.The loop protect is intended to prevent infinite loops to keep the browser from crashing and sometimes has false-positives.