rakesh830566

Prime Number

May 28th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.05 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Assignment 4.9</title>
  7. </head>
  8.  
  9. <body>
  10.     <h3>Write a program to check number is Prime or not</h3>
  11.     <hr>
  12.     <script type="text/javascript">
  13.         // Take input a number from user
  14.             var userInput = Number(prompt('Enter number to check it\'s Prime or not...'));
  15.  
  16.             // Displaying number which is entered by user
  17.             document.write('Entered number by you = <strong>' + userInput + '</strong><br><br>');
  18.  
  19.             // Checking number is Prime or not
  20.             var bool = true;
  21.             for (var i = 2; i < userInput; i++) {
  22.                if (userInput % i == 0) {
  23.                    bool = false;
  24.                    break;
  25.                }
  26.            }
  27.            if (bool) {
  28.                document.write('<strong>' + userInput + '</strong> is a Prime Number');
  29.             } else {
  30.                 document.write('<strong>' + userInput + '</strong> is not a Prime Number');
  31.             }
  32.     </script>
  33. </body>
  34.  
  35. </html>
Add Comment
Please, Sign In to add comment