Tell us what’s happening:
When I execute my code as below, I got the message:
// running tests
smallestMult(20) should return 232792560.
// tests completed
// console output
Potential infinite loop detected on line 4. Tests may be failing because of this.
Potential infinite loop detected on line 4. Tests may be failing because of this.
But when I execute my code on my machine (my PC), the output of smallestMult(20) is 232792560 (same with the answer of problem 5).
I don’t know where my wrong.
Your code so far
function smallestMult(n) {
let smallMul = n;
let isTrue = false;
while (!isTrue)
{
let count = 0;
for(let i = 1; i <= n; i++){
if(smallMul % i == 0){
count++;
}
}
if(count == n){
isTrue = true;
}
else{
smallMul++;
count = 0;
}
}
return smallMul;
}
smallestMult(20);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Challenge: Project Euler Problems 1 to 100 - Problem 5: Smallest multiple
Link to the challenge: