Advertisement
rikardoricz

Tomasz Świątek 4bti/2 tablice petle

Nov 21st, 2021
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // zad 1
  2.  
  3.   const a = parseInt(prompt("Podaj liczbe, aby obliczyc silnie:"));
  4.  
  5.   if (a < 0) {
  6.     console.log("Błąd! Nie ma silni z liczby < 0");
  7.   } else if (a == 0) {
  8.     console.log("0! = 1");
  9.   } else {
  10.     let strong = 1;
  11.     for (let i = a; i > 1; i--) {
  12.       strong *= i;
  13.     }
  14.     console.log(a + "! = " + strong);
  15.   }
  16.  
  17. // zad 2
  18.  
  19.  
  20.   for (let i = 10; i < 100; i++) {
  21.     if (i % 4 == 0) {
  22.       console.log(i);
  23.     }
  24.   }
  25.  
  26. // zad 3
  27.  
  28.   const step = parseInt(prompt("Podaj krok:"));
  29.   console.log("Krok = " + step + "- > ");
  30.   let i = 0;
  31.   while (i < 200) {
  32.     i += step;
  33.     if (i <= 200) console.log(i);
  34.   }
  35.  
  36. // zad 4
  37.  
  38.   let fiveNums = new Array(5);
  39.   for (let i = 0; i < fiveNums.length; i++) {
  40.     fiveNums[i] = parseInt(prompt("Podaj liczbę:"));
  41.   }
  42.   const total = fiveNums.reduce((a, b) => {
  43.     return a + b;
  44.   });
  45.   console.log("Suma: " + total + "</br>Elementy tablicy: "+ fiveNums.join());
  46.  
  47. // zad 5
  48.  
  49.   let foo = new Array;
  50.  
  51.   for (let i = 0; i >= 0; i++) {
  52.     foo[i] = parseInt(prompt("Podaj liczbe:"));
  53.     if (foo[i] == 0) {
  54.       break;
  55.     }
  56.  
  57.   }
  58.   const sortedFoo = foo.sort((a, b) => a-b);
  59.   console.log(`
  60.   MAX: ${foo[foo.length - 1]}
  61.   MIN: ${foo[0]}
  62.   SORT: ${sortedFoo}
  63.   `);
  64.  
  65. // zad 6
  66.  
  67.   let sum = 0;
  68.   let i = 0;
  69.   let num = 0;
  70.   while (sum < 50) {
  71.     num = parseInt(prompt("Podaj liczby:"));
  72.     sum += num;
  73.     i++;
  74.   }
  75.   if (sum > 50) {
  76.     sum -= num;
  77.     i--;
  78.   }
  79.   console.log("Suma liczb: " + sum + "</br> zsumowano " + i + " liczb");
  80.  
  81. // zad 7
  82.  
  83.   let money = 2;
  84.   let days = 1;
  85.   do {
  86.     money *= 2;
  87.     days++;
  88.   } while (days < 30);
  89.  
  90.   let formatter = new Intl.NumberFormat("pl-PL", {
  91.     style: "currency",
  92.     currency: "PLN",
  93.   });
  94.   fMoney = formatter.format(money);
  95.   console.log("Syn zaoszczędził " + fMoney);
  96.  
  97. // zad 8
  98.  
  99.   let base = 10;
  100.   let allBricks = 0;
  101.   let singleFloor = 0;
  102.   for (let i = base; i > 0; i--) {
  103.     singleFloor = Math.pow(i, 2);
  104.     allBricks += singleFloor;
  105.   }
  106.   console.log("Ilość cegieł w piramidzie: " + allBricks);
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement