Problem 5: Smallest multiple rounding error

Tell us what’s happening:

The code locally runs fine and tests correctly with all test cases.
When run in the freeCodeCamp window, the last test fils.
I assume this is a precision issue, but don’t know how to solve it.
I would like to stick with the algorithms I came up with. How do I circumvent this rounding error?

Your code so far


function smallestMult(n) {
    let smallest = n;
    while (! evenly_div(smallest, n)){
        smallest += n;
    }
    return smallest;
}

function evenly_div(x, a) {
    for (let i = 1; i < a; i++) {
        if ( x % i != 0) {
            return false;
        }
    }
    return true;
}

console.log(smallestMult(5));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-5-smallest-multiple

It is not a precision issue

You are triggering the infinite loop protection and your code is being stopped prematurely

You need a more efficient code so that your code doesn’t trigger it

Thanks for your response. Wouldn’t that trigger a warning?
I switched off the loop protection with //noprotect in the first line, to no avail.

//noprotect doesn’t work, and this kind of thing doesn’t trigger a warning

You can go to next thing, knowing you solved it anyway, even if it doesn’t pass the tests here, or try again