diff --git a/01/app.js b/01/app.js index e69de29..5a9ad56 100644 --- a/01/app.js +++ b/01/app.js @@ -0,0 +1,9 @@ +users = ["Paweł Sikorski", "Adam Niedzielski", "Tomek Kurek", "Aleks Baran", "Magda Sobota"] + +const firstElementOfArray = users[0] +console.log(firstElementOfArray) +const thirdElementOfArray = users[2] +console.log(thirdElementOfArray) +const fifthElementOfArray = users[4] +console.log(fifthElementOfArray) + diff --git a/02/app.js b/02/app.js index 9ad302b..594faa6 100644 --- a/02/app.js +++ b/02/app.js @@ -20,4 +20,12 @@ function createRandomArray() { function getRandomInteger(min, max) { return Math.round(Math.random() * (max-min) + min); -} \ No newline at end of file +} + +/* for(let i = 0; i < randomArray.length; i++) { + console.log(randomArray[i]) +} */ +function printElement(element) { + console.log(element) +} +randomArray.forEach(printElement) \ No newline at end of file diff --git a/03/app.js b/03/app.js index cebcbc2..394aa47 100644 --- a/03/app.js +++ b/03/app.js @@ -1,2 +1,17 @@ const n = 24; -const oddNumbers = []; \ No newline at end of file +const oddNumbers = []; + +function findRandomOddNumberInGivenRange(range) { + let number = 0; + while((number % 2 === 0)) { + number = Math.round(Math.random() * range) + } + return number +} + +for(let i = 0; i < n; i++) { + const number = findRandomOddNumberInGivenRange(n) + oddNumbers.push(number) + console.log(oddNumbers[i]) +} + diff --git a/04/app.js b/04/app.js index 8285afd..e235f52 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]; + +function findDiffrence(year) { + return 2024 - year +} + +const newMap = years.map(findDiffrence) + +for(let i = 0; i < newMap.length; i++) { + console.log(newMap[i]) +} + diff --git a/05/app.js b/05/app.js index 1c6bb90..fd82a60 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 EvenNumbers = numbers.filter(el => el % 2 === 0); +const sumOfNumbersFromArray = EvenNumbers.reduce((prev, curr) => prev + curr) + +console.log(sumOfNumbersFromArray) \ No newline at end of file