# Javascript Prime Number generator

Ever wanted to create a prime number generator? You can make a really basic one with Javascript, or use this approach to create one in a different programming language. Here's the basic code:

1//listof all prime numbers

2varprimes = [2];

3//current number

4varcurrent = 1;

5//functionto generate primes

6vargetPrimes =function(){

7//add 2 since even numbers are never primecurrent += 2;

8

9for(vari = 0; i < primes.length; i++){

10//cycle through generated prime numbersandcheckifthe current number is divisible by any of them

11if( current % primes[i] === 0){

12//number is divisible by a prime number

13return;

14 }

15 }

16//add the prime number to theprimes.push(current);array

17

18}

19

20//set interval to keep generating prime numberswindow.setInterval(getPrimes, 1);

21

To view the generated prime numbers, open the `Developer Console`

in your web browser (press `ctrl+shift+i`

for chrome), type in `primes`

and press enter.

That's it! Go crack some codes