Advertisement
Myknakryu

skrypt.js

Dec 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function przyciskMenu()
  2. {
  3.     document.write("<br/>");
  4.     var button = document.createElement("button");
  5. button.innerHTML = "PowrĂłt do menu";
  6. button.setAttribute("onclick","menu()");
  7. var body = document.getElementsByTagName("body")[0];
  8. body.appendChild(button);
  9. }
  10. function menu(){
  11. document.body.innerHTML = '';
  12. document.write("<ol><li>Wylicz sumę z n-dowolnych liczb</li>");
  13. document.write("<li>Wylicz średnią z liczb parzystych</li>");
  14. document.write("<li>Sprawdź czy wprowadzone liczby są liczbami pitagorejskimi")
  15. document.write("<li>SprawdĹş czy liczba jest pierwsza</li></ol><br/>")
  16. var button = document.createElement("button");
  17. button.innerHTML = "WybĂłr";
  18. button.setAttribute("onclick","wybor()");
  19. var body = document.getElementsByTagName("body")[0];
  20. body.appendChild(button);
  21. }
  22.  
  23. function suma()
  24. {
  25.     let x = prompt("Podaj ilość liczb");
  26.     let ilosc = parseInt(x);
  27.     let suma = 0;
  28.     for(let i = 1; i <= ilosc; i++){
  29.     x=prompt("Podaj liczbę " +i)
  30.     document.write(parseInt(x))
  31.     if(ilosc-i >= 1)
  32.         document.write("+");
  33.     suma += parseInt(x);
  34. }
  35. document.write("="+suma+"<br/>")
  36. }
  37.  
  38. function srednia()
  39. {
  40.     let x = prompt("Podaj ilość liczb");
  41.     let ilosc = parseInt(x);
  42.     let srednia = 0.0;
  43.     for(let i = 1; i <= ilosc; i++){
  44.     do
  45.     {
  46.     x=prompt("Podaj liczbę " +i)
  47.     y = parseFloat(x);
  48.     }while(x%2!=0)
  49.     srednia += y;
  50. }
  51.     srednia = srednia * 1.0 / ilosc;
  52.     document.write(srednia);
  53. }
  54.  
  55. function pitagorejskie(a, b ,c)
  56. {
  57.     return (a*a+b*b==c*c);
  58. }
  59.  
  60. function doPitagorejskich()
  61. {
  62.     let x = prompt("Podaj liczbę a");
  63. let a = parseInt(x);
  64. x = prompt("Podaj liczbę b");
  65. let b = parseInt(x);
  66. x = prompt("Podaj liczbę c");
  67. let c = parseInt(x);   
  68.  
  69.     document.write(a+"*"+a+"+")
  70.     document.write(b+"*"+b+"=")
  71.     document.write(c+"*"+c+" to wyraĹźenie jest ")
  72.     return pitagorejskie(a,b,c);
  73. }
  74.  
  75. function pierwsza(y, i = 2)
  76. {
  77.     if(i < y)
  78.     {
  79.         if(y % i != 0)
  80.             return(pierwsza(y, ++i));
  81.         else
  82.            return false;
  83.     }
  84.         return true;
  85. }
  86.  
  87.  
  88. function wybor()
  89. {
  90.     let x = prompt("Podaj wybĂłr: ")
  91.     x = parseInt(x);
  92.     document.body.innerHTML = '';
  93.     switch(x)
  94.     {
  95.         case 1:
  96.         suma();
  97.         przyciskMenu();
  98.         break;
  99.         case 2:
  100.         srednia();
  101.         przyciskMenu();
  102.         break;
  103.         case 3:
  104.         document.write(doPitagorejskich());
  105.         przyciskMenu();
  106.         break;
  107.         case 4:
  108.         let x = prompt("Podaj liczbę: ");
  109.         let y = parseInt(x);
  110.         document.write("Czy "+y+ " jest liczbą pierwszą: "+pierwsza(y));
  111.         przyciskMenu();
  112.         break;
  113.         default:
  114.         menu();
  115.     };
  116.  
  117. }
  118.  
  119. menu();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement