diff --git a/01/app.js b/01/app.js index e69de29..a497bfc 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,6 @@ +const users = ['Jan Kowalski', 'Monika Wysocka', 'Adam Nowak', 'Michał Ozimek', 'Dorota Rudzińska', 'Agata Borsuk']; + +console.log(users[0]); +console.log(users[2]); +console.log(users[4]); +console.log('Liczba elementów tablicy:', users.length); diff --git a/02/app.js b/02/app.js index 9ad302b..268de64 100644 --- a/02/app.js +++ b/02/app.js @@ -1,6 +1,20 @@ const randomArray = createRandomArray(); console.log(randomArray); +// wyświetlenie w konsoli wszystkich elementów tablicy przy pomocy pętli for + +for (let i = 0; i < randomArray.length; i++) { + console.log(randomArray[i]); +} + +// wyświetlenie w konsoli wszystkich elementów tablicy przy pomocy metody tablicowej .forEach() + +randomArray.forEach(el => console.log(el)); + +// wyświetl wartość ostatniego elementu tablicy +console.log(randomArray[randomArray.length - 1]); + + // nie modyfikuj kodu poniżej! @@ -9,15 +23,15 @@ console.log(randomArray); // ponieważ w JS występuje mechanizm tzw. hoisting-u function createRandomArray() { - const arr = []; - const len = getRandomInteger(1, 10) - for(let i=0; i currYear - year); + +console.log(newArr); diff --git a/05/app.js b/05/app.js index 1c6bb90..a666bb7 100644 --- a/05/app.js +++ b/05/app.js @@ -1 +1,5 @@ -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 evenSum = numbers.filter(num => num % 2 === 0).reduce((acc, curr) => acc + curr, 0); + +console.log(evenSum);