# Project Euler Problems 1 to 100 - Problem 5: Smallest multiple

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.

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);

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

Let’s apply conventional formatting:

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);

Usually, when you see “Potential infinite loop”, you either a) have an infinite loop or b) your loop is way too slow.

In this case, your problem is smalMul++ makes your loop take way too long. How could you make that part go faster?