var limit = 500; // The upper limit to search for primes up to.
var currentNum = 3; // The current number being checked (has to be set at 3 or 5, if you want to know why, let me know and I'll try and explain).
var primes = new Array(2,3); // The array used to store primes, the first two are given (they're needed for the script to work properly, again if you want to know why, ask me).
while( currentNum <= limit ){
for( i=1; currentNum % primes[i] > 0; i++ ){ // If the currentNum doesn't divide by the current prime then the loop runs.
if( primes[i] > Math.sqrt( currentNum ) ){ // If the current prime is greater than the square-root of the currentNum.
primes[primes.length] = currentNum; // currentNum is added to the prime array.
break; // The loop is broken.
}
}
currentNum = currentNum + 2; // We're only checking odd numbers so currentNum is incremented by 2.
}