Tell us what’s happening:
Looks like my logic can’t find the smallest multiple and end up in an infinite loop. Can someone point me to the right direction please?
Passing all the tests except the last one.
Your code so far
function smallestMult(n) {
// Good luck!
let isFound = false;
let currNumber = 0;
while(!isFound) {
// Add itself if it's not divisible
currNumber += n;
for(let i=n; i>=1; i--) {
// if currNumber is not divisible by numbers in range, break out of forloop
if(currNumber % i !== 0) {
break;
}
// currNumber is divisible by all numbers down to 1!
if(i===1)
isFound = true;
}
}
return currNumber;
}
smallestMult(20);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-5-smallest-multiple