Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkPrime(x){
- x = prompt("Enter the number to check", -3.2);
- if(isNaN(x)){ alert("Not a number"); return; }
- if(x<0){ alert("Negative number"); return; }
- if(x != parseInt(x)){ alert("Not an integer"); return; }
- var isPrime = true;
- if(x==0 || x==1){ isPrime = false;}
- for(i=2; i<x/2; i++){
- if((x%i) == 0){
- isPrime = false;
- }
- }
- alert(isPrime);
- return;
- }
- checkPrime();
Advertisement
Add Comment
Please, Sign In to add comment