diff --git a/01/app.js b/01/app.js index e69de29..9c1e12f 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,19 @@ +const users = [ + "Alex Carter", + "Jamie Reynolds", + "Morgan Hayes", + "Taylor Benson", + "Riley Sutton", + "Casey Mitchell", + "Jordan Fletcher", + "Avery Collins", + "Cameron Lawson", + "Dakota Pierce", +]; +console.log(` + 1st name: ${users[0]} + 3th name: ${users[2]} + 5th name: ${users[4]} + Users array: ${users} + Array length: ${users.length} + `); diff --git a/02/app.js b/02/app.js index 9ad302b..6f046b3 100644 --- a/02/app.js +++ b/02/app.js @@ -1,23 +1,34 @@ const randomArray = createRandomArray(); console.log(randomArray); +for (let i = 0; i < randomArray.length; i++) { + console.log(`Index ${i}: ${randomArray[i]}`); +} + +console.log("\n"); +randomArray.forEach(function (num, index) { + console.log(`Index ${index}: ${num}`); +}); +console.log("\n"); + +console.log(`Last element: ${randomArray[randomArray.length - 1]}`); // nie modyfikuj kodu poniżej! // funkcję może deklarować poniżej wywołania // ponieważ w JS występuje mechanizm tzw. hoisting-u function createRandomArray() { - const arr = []; - const len = getRandomInteger(1, 10) - for(let i=0; i counter) { + counter++; + if (counter % 2 == 1) { + oddNumbers.push(counter); + } + } + console.log(`n=${n} => ${oddNumbers}`); +} diff --git a/04/app.js b/04/app.js index 8285afd..10c863c 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 yearsPasst = years.map(function (year) { + return new Date().getFullYear() - year; +}); + +console.log(yearsPasst); diff --git a/05/app.js b/05/app.js index 1c6bb90..99bc36d 100644 --- a/05/app.js +++ b/05/app.js @@ -1 +1,7 @@ -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 sumOfEvenNumbers = numbers + .filter((num) => num % 2 == 0) + .reduce((acc, num) => (acc += num)); + +console.log(sumOfEvenNumbers);