| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // 第一步:定义一个函数
- // 定义一个函数,判断一个数是否为素数
- function fun(x) {
- for (var i = 2; i < x; i++) {
- if (x % i == 0) {
- return false;
- }
- }
- return true;
- }
- // 第二步:调用函数 判断100-1000之间的素数
- // 第三步:每6个数字换行
- var count = 0;
- for(var i=100;i<=1000;i++){
- if(fun(i)){
- document.write(i + " ");
- count++;
- if(count%6==0){
- document.write("<br>");
- }
- }
- }
- </script>
- </body>
- </html>
|