BlazejLZio

Funkcje JS

Mar 2nd, 2022 (edited)
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ZADANIE 1
  2. function wartoscBezwgledna (x){
  3.     if(Number.isInteger(x)==false){
  4.         return 'blad';}
  5.         else{
  6.            
  7.    
  8.     if(x>=0){
  9.         return x;
  10.     }
  11.     else{
  12.         const result=x* -1;
  13.         return result;
  14.     }
  15.     }
  16. }
  17. document.write(wartoscBezwgledna(3),'<br>');
  18. document.write(wartoscBezwgledna(-32),'<br>');
  19. document.write(wartoscBezwgledna(0.6));
  20.  
  21. ZADANIE 2
  22. function CzyParzysta (x){
  23.     if(Number.isInteger(x)==false){
  24.         return 'blad';}
  25.         else{
  26.            
  27.    
  28.     if(x%2==0){
  29.         return true;
  30.        
  31.     }
  32.     else{
  33.         return false;
  34.     }
  35.     }
  36. }
  37. document.write( CzyParzysta(3),'<br>');
  38. document.write(CzyParzysta(-32),'<br>');
  39. document.write(CzyParzysta(0.6));
  40.  
  41. ZADABUE 3
  42. function CzyParzysta (x,a){
  43.     if(Number.isInteger(x,a)==false){
  44.         return 'blad';}
  45.         else{
  46.             const wykładnik=x-1;
  47.             var pierwsza =+(Math.pow(10, wykładnik));  
  48.             var druga =+(Math.pow(10, x));
  49.             for(let d=pierwsza; d<druga;d++)
  50.             {
  51.                 if (d%a==0){
  52.                     document.write(d,'<br>');
  53.                 }
  54.             }
  55.    
  56.  
  57.  
  58.     }
  59. }
  60. var m=+prompt("wpisz ilo liczbowa liczba");
  61. var y=+prompt("wpisz przeco ma się dizelić");
  62. document.write( CzyParzysta(m,y),'<br>');
  63.  
  64.  
  65.  
  66. ZADANIE 4
  67. function CzyParzysta (x){
  68.     if(Number.isInteger(x)==false){
  69.         return 'blad';}
  70.         else{
  71.             let y=x-1;
  72.             if(x==2||x==1){
  73.                 return 1;
  74.             }
  75.             do  {
  76.                 if (x%y==0){
  77.                     return 0;
  78.                 }
  79.                 y=y-1;
  80.             }while(y>1)
  81.             if(y==1 ){
  82.                 return 1;
  83.             }
  84.             }
  85.    
  86.  
  87.  
  88.    
  89. }
  90. var m=+prompt("wpisz liczba");
  91.  
  92. if (CzyParzysta(m)==1){
  93.    document.write ('pierwsza');
  94. }
  95. else
  96. {
  97.     document.write ('nie pierwsza')
  98. }
  99.  
  100.  
  101. ZADNIE 5
  102. function liczbaCyfr (x){
  103.     var y=0;
  104.           do{
  105.                 x=x/10;
  106.                 y=y+1;
  107.                
  108.           }
  109.           while(x>=0.1)
  110. return y-1;
  111.  
  112.    
  113. }
  114. var m=+prompt("wpisz liczba");
  115.  
  116. document.write(liczbaCyfr(m));
  117.  
Add Comment
Please, Sign In to add comment