diff --git a/01/app.js b/01/app.js index e69de29..b3f9413 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,8 @@ +const users = ["Adam kowalski", "Jan Brzoza", "Sandra Malinowska", "Nikola Matlik", "Wiktoria Wiśniowska"]; + +for(let i = 0; i < users.length; i++){ + if(i % 2 === 0){ + console.log(users[i]) + } +} +console.log("tablica zawiera: " + users.length + " elementów"); \ No newline at end of file diff --git a/02/app.js b/02/app.js index 9ad302b..976f63b 100644 --- a/02/app.js +++ b/02/app.js @@ -20,4 +20,16 @@ function createRandomArray() { function getRandomInteger(min, max) { return Math.round(Math.random() * (max-min) + min); -} \ No newline at end of file +} + +console.log("Wyświetlenie wszystkich elementów tablicy przy pomocy pętli for: ") + +for(let i = 0; i < randomArray.length; i++){ + console.log(randomArray[i]); +} + +console.log("Wyświetlenie wszystkich elementów tablicy przy pomocy metody foreach") + +randomArray.forEach(element => { + console.log(element) +}); \ No newline at end of file diff --git a/03/app.js b/03/app.js index cebcbc2..a5d9ff3 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 n = 100; +const oddNumbers = []; + +for(let i = 0; i <= n; i++){ + if( i > 0 && i % 2 ===1){ + oddNumbers.push(i); + } +} + +console.log(oddNumbers); \ No newline at end of file diff --git a/04/app.js b/04/app.js index 8285afd..899e7df 100644 --- a/04/app.js +++ b/04/app.js @@ -1 +1,11 @@ -const years = [1980, 1934, 2002, 2019]; \ No newline at end of file +const years = [1980, 1934, 2002, 2019]; + +const numbersOfYears = years.map(calcNumberOfYears); + +function calcNumberOfYears(element, index, array){ + const currentYear = new Date().getFullYear(); + return currentYear - element; +} + +console.log(numbersOfYears) + diff --git a/05/app.js b/05/app.js index 1c6bb90..4a9cd8b 100644 --- a/05/app.js +++ b/05/app.js @@ -1 +1,12 @@ -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 evenNumbers = numbers.filter((number) => { + if(number % 2 === 0){ + return number; + } +}) + +const sum = evenNumbers.reduce(function(prevValue, currentValue){ + return prevValue + currentValue; +}); + +console.log(sum) \ No newline at end of file