My solution to this problem works in the console for all the test cases but it says that the last 2 cases (13 and 20) are incorrect. What’s going on?

Your code so far

function smallestMult(n) {
let nums = [];
for (let a = 1; a <= n; a++) {
nums.push(a);
}
for (let a = n;; a++) {
if (nums.every(elem => a % elem === 0)) {
return a;
}
}
}
smallestMult(13);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Your code is not efficient enough. The FCC editor has protections that stop the code from running if it is needing too much time, and those are being triggered by your code

While this is technically correct, this ‘solution’ is not conducive to a good learning experience. Students are spending time trying to incorrectly troubleshoot their logic while it is the coding environment that is to blame for their failures. There is no error to this effect and you cannot log the error. The solution to this isn’t “Your code is not efficient enough”. Coding efficiency is not a requirement of the exercise.

Even if that may be true you can’t pass the tests if your code is not efficient enough. You can bring this up in the GitHub repository if you want and if there is not an issue on the same topic (if there is one comment there)

Your “brute force” algorithm for determining primes is not efficient. Even with the brute force algorithm, you only need to go up to sqrt(num) when checking for primality, not num.

You should look up “Sieve of Erosthanes” for a much faster solution, though at the expense of more memory – the “1001th prime” solution will require a more clever algorithm than keeping the whole sieve in memory. It’s a tough one. Hint: it’s pretty likely the Miller-Rabin primality test will be accurate up to the 1001st prime, though I’m not 100% sure of that.