title: How do I calculate prime numbers using JavaScript?
body: <p>For my JavaScript course at school, my assignment is to calculate the first 10 prime numbers.  The instructions specifically say not to use an array to store them or the assignment will result in a zero.  I thought I had my logic worked out, but maybe not.  The code below results in <code>3,4,5,5,5,6,6,7,7,7,7,7</code>  Pretty obvious that it's not correct because 4 and 6 are not prime numbers and also that there are duplicates.  Also, it outputs 12 numbers when the requirement is 10.  What's gone wrong?</p>
  
  <pre><code>function primeNumbers(){
  
              var primeNumbers = []; /* Where the prime numbers are stored */
  
              for(var dividend = 0; primeNumbers.length &lt;= 10; dividend++){
  
                  for(var divisor = 0; divisor &lt;= dividend; divisor++){
  
                      if(dividend % divisor &gt; 0){
  
                          primeNumbers.push(dividend);
  
                      }
  
                  }
  
              }
  
              console.log(primeNumbers.join());
  
          }
  </code></pre>