I am writing a JavaScript that prints the prime numbers between 1 and 999 in a table that consists of 10 columns. 

Once the counter variable reaches a value of 10 (meaning that 10 cells have been added to the current row ) then I print `</tr><tr>` to start a new row and reset the variable to 0.
I have been trying and I managed to print the prime numbers in the table but now to create a new row after every 10 columns is where I am failings. 

Any assistance will be appreciated . 

Below is my code.

```
<html>
    <head>
        <script language="javascript">
            document.write("<table border='1'>");
            document.write("<tr>");
            for(n = 0 ; n < 1000; n++){
                var x=1;
                if(n==0 || n==1) x=0;
                for(i=2;i<n;i++)
                {
                    if(n%i==0)
                    {
                        x=0;
                        break;
                    }
                }
                if(x==1)
                {
                    document.write("<td>"); 
                    // if prime print the numbers 
                    document.write(n);
                    document.write("</td>");
                }
                else
                { 
                // if not prime number do nothing 
                }
            }  
            document.write("</table>");
        </script>
    </head>
    <body>
   </body>
</html>

```