Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Assignment 4.9</title>
- </head>
- <body>
- <h3>Write a program to check number is Prime or not</h3>
- <hr>
- <script type="text/javascript">
- // Take input a number from user
- var userInput = Number(prompt('Enter number to check it\'s Prime or not...'));
- // Displaying number which is entered by user
- document.write('Entered number by you = <strong>' + userInput + '</strong><br><br>');
- // Checking number is Prime or not
- var bool = true;
- for (var i = 2; i < userInput; i++) {
- if (userInput % i == 0) {
- bool = false;
- break;
- }
- }
- if (bool) {
- document.write('<strong>' + userInput + '</strong> is a Prime Number');
- } else {
- document.write('<strong>' + userInput + '</strong> is not a Prime Number');
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment