diff --git a/01/app.js b/01/app.js index e69de29..9b23dd8 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,10 @@ +const users = new Array("John Doe", "John Smith", "Joe Bonamassa", "Mia Davis", "Ava Miller"); + + +console.log(`Pierwsza pozycja w zmiennej 'users' to: ${users[0]}`); +console.log(`Trzecia pozycja w zmiennej 'users' to: ${users[2]}`); +console.log(`Piąta pozycja w zmiennej 'users' to: ${users[4]}`); + + +console.log(`Zmienna 'users' zawiera: ${users.length} pozycji`); + diff --git a/02/app.js b/02/app.js index 9ad302b..1e9f99f 100644 --- a/02/app.js +++ b/02/app.js @@ -2,6 +2,15 @@ const randomArray = createRandomArray(); console.log(randomArray); +for (let j = 0; j < randomArray.length; j++) { + console.log(`Pozycja nr ${j + 1}: ${randomArray[j]} === for(){} ===`); +}; + +randomArray.forEach((e, i) => { + console.log(`Pozycja nr ${i + 1}: ${e} === forEach() ===`); +}); + +console.log(`Ostatnia pozycja w 'randomArray to: '${randomArray[randomArray.length - 1]}`); // nie modyfikuj kodu poniżej! @@ -11,13 +20,13 @@ console.log(randomArray); function createRandomArray() { const arr = []; const len = getRandomInteger(1, 10) - for(let i=0; i { + console.log(`Index: ${i}; Wartość: ${e}`); +}); \ No newline at end of file diff --git a/04/app.js b/04/app.js index 8285afd..b142933 100644 --- a/04/app.js +++ b/04/app.js @@ -1 +1,12 @@ -const years = [1980, 1934, 2002, 2019]; \ No newline at end of file +const years = [1980, 1934, 2002, 2019]; + +const yearPoint = parseInt(prompt('Podaj rok, który będzie punktem odniesienia')); + +if (!yearPoint | yearPoint < 0) { + alert('Wprowadzono niepoprawny format danych odśwież stronę i spróbuj jeszcze raz!'); +} else { + const newYears = years.map((e) => e - yearPoint); + newYears.forEach((e, i) => { + console.log(`Między datą nr. ${i + 1} a punktem odniesienia jest ${e} lat różnicy`) + }); +} \ No newline at end of file diff --git a/05/app.js b/05/app.js index 1c6bb90..394c321 100644 --- a/05/app.js +++ b/05/app.js @@ -1 +1,9 @@ -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(e => e % 2 === 0); + +const sum = evenNumbers.reduce((total, currentValue) => { + return total += currentValue +}); + +console.log(`The sum of the even numbers inside "numbers" array is: ${sum}`); \ No newline at end of file