diff --git a/01/app.js b/01/app.js index e69de29..e2b05cd 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,7 @@ +users = ['Jan Kowalski', 'Piotr Nowak', 'Zofia Kowalska', 'Anna Jankowska', 'Zygmunt Jakiś', 'Barbara Torba', 'Marianna Cymbał'] + +console.log(users[0]) +console.log(users[2]) +console.log(users[4]) + +console.log(users.length) \ No newline at end of file diff --git a/02/app.js b/02/app.js index 9ad302b..b97ea96 100644 --- a/02/app.js +++ b/02/app.js @@ -20,4 +20,17 @@ function createRandomArray() { function getRandomInteger(min, max) { return Math.round(Math.random() * (max-min) + min); -} \ No newline at end of file +} + +console.log("Wyświetlanie elementów tablicy za pomocą pętli `for`:"); +for (let i = 0; i < randomArray.length; i++) { + console.log(randomArray[i]); +} + +console.log("Wyświetlanie elementów tablicy za pomocą metody `.forEach()`:"); +randomArray.forEach((element) => { + console.log(element); +}); + +const lastElement = randomArray[randomArray.length - 1]; +console.log("Ostatni element tablicy:", lastElement); \ No newline at end of file diff --git a/03/app.js b/03/app.js index cebcbc2..82f5203 100644 --- a/03/app.js +++ b/03/app.js @@ -1,2 +1,10 @@ const n = 24; -const oddNumbers = []; \ No newline at end of file +const oddNumbers = []; + +for (let i = 1; i <= n; i++) { + if (i % 2 !== 0) { + oddNumbers.push(i); + } +} + +console.log("Tablica liczb nieparzystych:", oddNumbers); \ No newline at end of file diff --git a/04/app.js b/04/app.js index 8285afd..573c016 100644 --- a/04/app.js +++ b/04/app.js @@ -1 +1,7 @@ -const years = [1980, 1934, 2002, 2019]; \ No newline at end of file +const years = [1980, 1934, 2002, 2019]; + +const currentYear = new Date().getFullYear(); + +const yearsPassed = years.map(year => currentYear - year); + +console.log(yearsPassed); \ No newline at end of file diff --git a/05/app.js b/05/app.js index 1c6bb90..30514a6 100644 --- a/05/app.js +++ b/05/app.js @@ -1 +1,8 @@ -const numbers = [1, 2, 3, 4, 5, 6, 7]; \ No newline at end of file +const numbers = [1, 2, 3, 4, 5, 6, 7]; + + +const evenNumbersSum = numbers + .filter(number => number % 2 === 0) + .reduce((sum, number) => sum + number, 0); + +console.log(evenNumbersSum); \ No newline at end of file