Problem 7: 10001st prime zxc

Tell us what’s happening:

The result of nthPrime(10001) is different from the real result (FreeCodeCamp interpreter shows 84143 )

What is the problem?

Your code so far

function nthPrime(n) {
    let primeCounter = 1
    let i
    for (i = 3; primeCounter != n; i+=2){
        if (isPrime(i)) primeCounter++
    function isPrime (number) {
        for (let j = 3; j <= number/j; j+=2){
            if (!(number % j)) return false
        return true
    return i-2


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36.

Link to the challenge:

If your solution is inefficient, it may stop executing before it is actually done. This is because fCC has a timeout to protect students from accidentally crashing their browser with an infinite loop.

As far as I remember FCC’s solution hits timeout as well, so there’s no definitive JS solution at this moment. I remember spending hours on this problem and eventually dropping it :slight_smile: