Advertisement
desito07

Prime Number Checker

May 25th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. function primeNumberChecker(n) {
  2. if (n == 2 || n == 3 || n == 5 || n == 7) {
  3. console.log("true");
  4. } else if (n < 2 || n % 2 == 0) {
  5. console.log("false");
  6. } else {
  7. for (let i = 3; i <= Math.sqrt(n); i += 2) {
  8. if (n % i == 0) {
  9. console.log("false");
  10. } else {
  11. console.log("true");
  12. }
  13. }
  14. }
  15. }
  16. primeNumberChecker(7);
  17. primeNumberChecker(8);
  18. primeNumberChecker(81);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement