# Project Euler: Problem 7: 10001st prime help please

Hello campers , I got stuck on this challenge , I found a solution but it is not effecient ,because it goes into too much loop

``````function nthPrime(n) {
// Good luck!
let counter=0;
let primes=[2];
let i=0;
let num=2;
while(i<20000){
num+=1;
for(let j=0;j<primes.length;j++){
if(/\d{1,}(?=\.)/g.test(num/primes[j])){
counter+=1;
}
}
if(counter===primes.length){
primes.push(num);
counter=0;
}
if(primes.length===n){
return primes[primes.length-1];
}
else {
counter=0;
}
i++
}
}

nthPrime(10001);
``````

I donâ€™t know any algorithm rather than this one , maybe because I m not good in math
the algorithm that I am using here is i is looing if num=3 num/primes[ j ] wich is 3/2
counter incremented
then if counter ===primes.length means that this number is prime
and to stop i looping if I find primes.length===n the function returns and stop everything
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-7-10001st-prime