Advertisement
Morlom

Zadanie 4 - funkcje

Jan 25th, 2022
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     var liczba;
  3.     function LICZBA_PIERWSZA(liczba) {
  4.         var count = 0;
  5.         for (let i = 1; i <= liczba; i++) {
  6.             if (liczba%i == 0) {
  7.                 count = count + 1;
  8.             }
  9.         }
  10.         if (count == 2) {
  11.             return 1;
  12.         }
  13.         else {
  14.             return 0;
  15.         }
  16.     }
  17.  
  18.     function check(liczba) {
  19.         if (LICZBA_PIERWSZA(liczba) == 1) {
  20.         document.write(liczba+ " jest liczbą pierwszą<br>");
  21.         }
  22.         else {
  23.         document.write(liczba+ " nie jest liczbą pierwszą<br>");
  24.         }
  25.     }
  26.  
  27.     check(7);
  28.     check(6);
  29.     check(23);
  30. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement