JS is judged whether the number is a prime number

<script>
@ Primes: 1 and itself in addition, no other number is called the number of divisible it can be such a prime number
// define a random number
var num = + prompt ( "Please enter a positive integer greater than 2");
// define a variable mark this tag variables can be responsible if there is divisible by the number of marks in circulation
var ISZ = true;
for ( var i = 2; i <Num; i ++) {
if (num % i === 0) {
// Description from between 2-10 can be several then it is not a prime number divisible by 11
ISZ = false;
}
}
// If true judgment isZ explanation cycle if statement did not enter it means that there is no number divisible by 11
if (isZ) {
alert (num + "is a prime number");
} else {
alert (num + "is not a prime number");
}
</script>

Guess you like

Origin www.cnblogs.com/zz22/p/11402276.html