js函数判断100到两百以内的所有质数
<!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 fn(n){
var flag=true;
for (var i=2;i<=n-1;i++){
if(n%i===0){
flag=false;
break;
}
}
return flag;
}//判断函数是不是质数
function fun(a,b){
for(var i=a;i<=b;i++){
var res=fn(i)
if(res){
console.log(i+'是质数');
}
}
}
fun(100,200);
</script>
</body>
</html>