Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ZADANIE 1
- function WARTOSC_BEZWZGLEDNA(a){
- if(a < 0){
- document.write(-a)
- }
- else {
- document.write(a);
- }
- }
- WARTOSC_BEZWZGLEDNA(-4);
- //ZADANIE 2
- function CZY_PARZYSTA(a){
- if (a % 2 === 0){
- return true;
- }
- else{
- return false;
- }
- }
- document.write(CZY_PARZYSTA(5));
- // ZADANIE 3
- function SZLACZEK (length, char) {
- for (let i = 0; i < length; i++){
- document.write(char);
- }
- }
- SZLACZEK(5, "*");
- //ZADANIE 4
- let PODZIELNOSC = (numb1, numb2) => {
- for (let i = 10 ** numb1 - 1; i >= 10 ** (numb1 - 1); i--){
- if(i % numb2 === 0) document.write(i + ", ");
- }
- }
- PODZIELNOSC(2, 5);
- //ZADANIE 5
- function OBWOD_TROJKATA(a, b, c){
- if(a + b > c && a + c > b && b + a > c && b + c > a && c + a > b && c + b > c){
- let result = a + b + c;
- document.write(result);
- }
- else{
- alert("Nie można stworzyć takiego trójkąta")
- document.write(-1);
- }
- }
- OBWOD_TROJKATA(4, 6, 9)
- //ZADANIE 6
- function Silnia(n){
- silnia = 1;
- for (let i = 1; i <= n; i++){
- silnia *= i;
- }
- document.write(silnia);
- }
- Silnia(5);
- //ZADANIE 7
- function LICZBA_PIERWSZA(n) {
- if (n === 2 || n === 1){
- alert("Podana liczba nie jest pierwsza")
- return 0;
- }
- for(let i = 3; i < n; i++){
- if(n % i === 0){alert("Podana liczba nie jest pierwsza")
- return 0;
- }
- }
- alert(`Podana liczba "${n}" jest pierwsza`)
- return 1;
- }
- document.write(LICZBA_PIERWSZA(1619));
- // ZADANIE 8
- function LICZBA_CYFR(a){
- let result = a.toString();
- document.write(result.length);
- }
- LICZBA_CYFR(22);
- // ZADANIE 9
- function SUMA_CYFR(a){
- let result = a.toString();
- let array = result.split("");
- let sum = 0;
- for(let i = 0; i < array.length; i++){
- sum += parseInt(array[i]);
- }
- document.write(sum + "<br>");
- if (sum > 9){
- SUMA_CYFR(sum);
- }
- }
- SUMA_CYFR(254364356);
- //ZADANIE 10
- function FIBBONACCI (n){
- let numb1 = 1;
- let numb2 = 1;
- let next;
- for (let i = 1; i <= n; i++) {
- document.write(numb1 + " ");
- next = numb1 + numb2;
- numb1 = numb2;
- numb2 = next;
- }
- }
- FIBBONACCI(10);
- //ZADANIE Z POTĘGĄ Z LEKCJI ALE BEZ REKURENCJI
- function POTĘGA(down, up){
- let result = Math.pow(down, up);
- document.write(result);
- }
- POTĘGA(2, 5);
Advertisement
Add Comment
Please, Sign In to add comment