Tell us what’s happening:
The result of nthPrime(10001) is different from the real result (FreeCodeCamp interpreter shows 84143 ) https://repl.it/@CharonIV/Project-Euler-Problem-7-10001st-prime
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
}
console.log(nthPrime(10001));
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: