reenadak

2019-05-19_check_prime_number

May 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkPrime(x){
  2. x = prompt("Enter the number to check", -3.2);
  3.  
  4. if(isNaN(x)){ alert("Not a number"); return; }
  5. if(x<0){ alert("Negative number"); return; }
  6. if(x != parseInt(x)){ alert("Not an integer"); return; }
  7.  
  8.  
  9. var isPrime = true;
  10.  
  11. if(x==0 || x==1){ isPrime = false;}
  12.  
  13. for(i=2; i<x/2; i++){
  14.     if((x%i) == 0){
  15.         isPrime = false;
  16.     }
  17. }
  18. alert(isPrime);
  19. return;
  20.  
  21. }
  22.  
  23. checkPrime();
Advertisement
Add Comment
Please, Sign In to add comment