求100以内的质数
/* For every number from 0 to 100, do the following: */ for (var counter = 0; counter <= 100; counter++) { /* Loop through values from 2 to 1 before the counter. */ for (var i = 2; i <= counter-1; i++) { /* if the remainder of dividing counter by the current value of `i` is zero, * we know we don't have a prime, so break out of the loop: */ if (counter%i === 0) break; } /* If the loop completed and `i` is equal to the counter, that means counter is not * divisible by anything except for 1 and itself, making it prime */ if(i === counter) console.log(counter); }