Problem 7: 10001st prime

Tell us what’s happening:
My code cannot pass the test: nthPrime(10001)
It stops at i = 94709 and it should pass the test if it can reach 104743.
I cannot think of any way to improve the speed of the algorithm.
Please help.

Your code so far

function nthPrime(n) {
  let primeList = [2];
  let i = 3;
  while(primeList.length < n){
    let j = 0;
    let isPrime = true;
    let bound = parseInt(Math.sqrt(i));
    while(primeList[j] <= bound){
      if(i % primeList[j] == 0){
        isPrime = false;
  return primeList[primeList.length - 1];

Your browser information:

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

Link to the challenge:

Hi @LucasChau, I tested your solution in Chrome and Firefox. I’m also getting failure in Firefox, but Chrome is working. This doesn’t explain why it’s not passing, exactly, but I hope it helps you figure out what’s going on.

Thanks for your help. In my computer, my solution does not work in Chrome, Firefox and IE with Chrome having the closest value. I doubt that the tests depend on computer performance or network speed.