Advertisement
MarcinMolenda

ZadaniaJSfunkcje

Jan 28th, 2021 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Zadanie 1
  2.  
  3. function wartoscbezwzgledna(x) {
  4.     if (x>0)
  5.     return x;
  6.     else return x*-1;
  7. }
  8. document.write (wartoscbezwzgledna(-10));
  9.  
  10. //Zadanie 2
  11.  
  12. function CZY_PARZYSTA(x) {
  13.     if (x%2==0)
  14.     return 'Parzysta';
  15.     else
  16.     return 'Nieparzysta';
  17. }
  18. document.write (CZY_PARZYSTA(-10));
  19.  
  20. //Zadanie 3
  21.  
  22. function SZLACZEK(x,y)
  23. {
  24. for (var i=0;i < x;i++)
  25. {document.write(y);}
  26. }
  27. SZLACZEK(10,'@')
  28.  
  29. //Zadanie 4
  30.  
  31. function PODZIELNOSC(x,y)
  32. {
  33.     for (var i=Math.pow(10,x-1);i < Math.pow(10,x);i++)
  34. {
  35.    if(i%y==0)
  36.     {
  37. document.write(i+' ');
  38.     }
  39. }
  40.  
  41. }
  42. PODZIELNOSC(3,87);
  43.  
  44. //Zadanie 5
  45.  
  46. function OBWOD_TROJKATA(x,y,z)
  47. {  
  48.     if (x+y>z && x+z>y && y+z>x)
  49.     return('Obwód trójkąta to: '+(x+y+z));
  50.     else
  51.     return(-1+'</br>'+'nie da się utworzyć trójkąta');
  52. }
  53. document.write(OBWOD_TROJKATA(5,12,13));
  54.  
  55.  
  56. //Zadanie 6
  57.  
  58. function SILNIA(x)
  59. {
  60.     if (x == 1 || x == 0)
  61.     return 1;
  62.   for (var i= x-1; i>=1; i--)
  63.   {
  64.     x *= i;
  65. }  
  66.   return x;
  67. }
  68. document.write(SILNIA(5));
  69.  
  70. //Zadanie 7
  71.  
  72. function LICZBA_PIERWSZA(x){
  73. for(var dzielniki=2;dzielniki<x;dzielniki++){
  74. if(x%dzielniki===0){
  75. document.write(x+' nie jest liczbą pierwszą');
  76. return false;
  77. }
  78. }
  79. document.write(x+' to liczba pierwsza');
  80. return true;
  81. }
  82. LICZBA_PIERWSZA(12);//należy podać liczbę większą od 1
  83.  
  84. //Zadanie 8
  85.  
  86. function LICZBA_CYFR(x)
  87. {  
  88. liczba = 1;
  89. while((x=x/10) >=1)
  90. {
  91. liczba++
  92. }
  93. return liczba;
  94. }
  95. document.write(LICZBA_CYFR(9999));
  96.  
  97. //Zadanie 10
  98.  
  99. function FIBONACCI(n)
  100. {
  101.     if (n == 0)
  102.     return 0;
  103.     else if (n==1)
  104.         return 1;
  105.     else
  106.     return FIBONACCI(n-1)+FIBONACCI(n-2);
  107. }
  108. document.write(FIBONACCI(7));
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement