4.1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
let num=parseInt(prompt("请输入一个数字"));
let isPrime = true;
for (let i = 2; i < num; i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
console.log(num + '是质数')
} else {
console.log(num + '不是质数')
}
</script>
</body>
</html>
4.2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
//利用isPrime函数找出循环100-999之间的质数
let a=1
function isPrime(num) {
for(let i = 2; i<num;i++){
if (num % i==0){
console.log(num+'不是质数')
a=0
break
}
}
if(a==1){
console.log(num='是质数')
}
}
for(let num= 100;num< 1000;num++){
isPrime(num)
}
</script>
</body>
</html>
4.3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
for(var i = 100;i < 1000; i ++){
var a = parseInt(i / 100)
var b = parseInt(i % 100 / 10)
var c = i % 10
if(i==a*a*a+b*b*b+c*c*c){
console.log(i+'是一个水仙花数')
}
}
</script>
</body>
</html>