JSFiddle - React, Tailwind, and code Playground
JavaScript
function isPrime(n) {
if( n < 2) return false;
// a number is prime if it is divisible only by 1 and itself.
// so, let's check it
var rt = Math.sqrt(n), i;
for( i=2; i<=rt; i++) {
if( n%i == 0) {
// the number is divisible by something else.
return false;
}
}
return true;
}
var tbl = document.createElement('table'),
tbd = tbl.appendChild(document.createElement('tbody')),
tr, td, i, found = 0;
for( i=2; i<1000; i++) { // we can start at 2, because as I said earlier 1 is not prime
if( isPrime(i)) {
// if the number of found numbers is a multiple of 10, start a new row
// the first prime we find will be "number 0", which is divisible by 10.
if( found % 10 == 0) tr = tbd.appendChild(document.createElement('tr'));
td = tr.appendChild(document.createElement('td'));
td.appendChild(document.createTextNode(i));
found++;
}
}
if( found % 10 != 0) {
td = tr.appendChild(document.createElement('td'));
td.colSpan = 10 - found % 10;
}
document.body.appendChild(tbl);
tbl.setAttribute("border",1);