From 98c377697391d0a1aa61426c7d61827ff86832b9 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Tue, 7 Mar 2023 12:41:16 +0000 Subject: [PATCH 1/9] javaScriot-Core-1-Coursework-Week3 update --- 1-exercises/A-undefined/exercise.js | 9 ++--- 1-exercises/C-array-get-set/exercises2.js | 2 +- 1-exercises/D-for-loop/exercise.js | 5 +++ 2-mandatory/1-weather-report.js | 10 ++++++ 2-mandatory/2-financial-times.js | 41 +++++++++++++++++++++++ 5 files changed, 62 insertions(+), 5 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..076fc9f6 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,12 +11,12 @@ // Example 1 let a; -console.log(a); +console.log(a); //it will be undefined because it does not have any value // Example 2 function sayHello() { - let message = "Hello"; + let message = "Hello"; //hello is not a string in console.log, so the program reads it as variable, but "hello" doesn't exist. } let hello = sayHello(); @@ -28,9 +28,10 @@ function sayHelloToUser(user) { console.log(`Hello ${user}`); } -sayHelloToUser(); +sayHelloToUser(); //when calling function we don't pass any value for parameter user + // Example 4 let arr = [1,2,3]; -console.log(arr[3]); +console.log(arr[3]); //element in arr with index 3 doesn't exist. There only 0, 1, 2. diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..a8cc3c29 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -6,7 +6,7 @@ - change the first value in the array to the number 1 */ -let numbers = [1, 2, 3]; // Don't change this array literal declaration +let numbers = [2, 3, 4]; // Don't change this array literal declaration /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/D-for-loop/exercise.js b/1-exercises/D-for-loop/exercise.js index 081002b2..7c31cd44 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -37,3 +37,8 @@ Jane Austen is 41 years old Bell Hooks is 63 years old Yukiko Motoya is 49 years old */ +const AGES = [59, 40, 41, 63, 49]; + +for (let i = 0; i < WRITERS.length; i++) { + console.log(WRITERS[i] + " is " + AGES[i] + " years old"); +} \ No newline at end of file diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..ebf033c5 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,16 @@ function getTemperatureReport(cities) { // TODO + let arr = []; + let degree = 0; + let cityDegree = ""; + for (let i = 0; i < cities.length; i++) { + degree = temperatureService(cities[i]); + cityDegree = `The temperature in ${cities[i]} is ${degree} degrees`; + arr.push(cityDegree); + } + return arr; + } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..a8b92947 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -6,6 +6,17 @@ */ function potentialHeadlines(allArticleTitles) { // TODO + function potentialHeadlines(allArticleTitles) { + // TODO + let shortArticles = []; + for (let article of allArticleTitles) { + if (article.length <= 65) { + shortArticles.push(article); + } + } + return shortArticles; +} + } /* @@ -15,6 +26,14 @@ function potentialHeadlines(allArticleTitles) { */ function titleWithFewestWords(allArticleTitles) { // TODO + const myArray = []; + for (let article of allArticleTitles) { + myArray.push(article.split(" ")); + } //newArray takes individual words are elements + let result = myArray.reduce(function (a, b) { + return a.length <= b.length ? a : b; //compares length of arrays in newArray -> how many words in each array & assigns shortest array to the variable result + }); + return allArticleTitles[myArray.indexOf(result)]; //myArray.indexOf(result) -> returns index of result in newArray, which is the same index in allArticleTitles -> returns the title. } /* @@ -24,18 +43,40 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + let countArray = []; + for (article of allArticleTitles) { + countArray.push(article.length); + } + let sum = 0; + for (let i = 0; i < countArray.length; i++) { + sum += countArray[i]; + } + return Math.round(sum / countArray.length); } + + + /* The Financial Times wants to understand what the average number of characters in an article title is. Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { // TODO + let countArray = []; + for (article of allArticleTitles) { + countArray.push(article.length); + } + let sum = 0; + for (let i = 0; i < countArray.length; i++) { + sum += countArray[i]; + } + return Math.round(sum / countArray.length); } + /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ "Streaming wars drive media groups to spend more than $100bn on new content", From 34f40ceabc770740b24ca29a71872692dffb11af Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:44:18 +0000 Subject: [PATCH 2/9] JavaScriot-core-1-Coursework-week3 update mandatory --- 2-mandatory/3-stocks.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..d0e61cf7 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -35,8 +35,16 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ */ function getAveragePrices(closingPricesForAllStocks) { // TODO + let averageOfWeek = []; + //looping through array of arrays and calling findAveragePrice method on each array + for (let averageOfWeek of closingPricesForAllStocks) { + averageOfWeek.push(findAveragePrice(averageOfWeek)); + } + return averageOfWeek; } + + /* We also want to see what the change in price is from the first day to the last day for each stock. Implement the below function, which @@ -49,6 +57,13 @@ function getAveragePrices(closingPricesForAllStocks) { */ function getPriceChanges(closingPricesForAllStocks) { // TODO + let result =[]; + + for( let i = 0; i< closingPricesForAllStocks.length; i++) { + let diff =0; + diff = closingPricesForAllStocks[i][4] - closingPricesForAllStocks[i][0]; + result.push(parseFloat(diff.toFixed(2))); + } } /* @@ -65,6 +80,19 @@ function getPriceChanges(closingPricesForAllStocks) { */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { // TODO + + let arr = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + arr.push( + `The highest price of ${stocks[ + i + ].toUpperCase()} in the last 5 days was ${Math.max( + ...closingPricesForAllStocks[i] + ).toFixed(2)}` + ); + } + return arr; + } From 27c8fc8cbd989523b2b90046b3cf2429051c1eeb Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:22:00 +0000 Subject: [PATCH 3/9] JavaScript-core-1-coursework-week3 update exercises week3 --- 1-exercises/B-array-literals/exercise.js | 4 ++-- 1-exercises/C-array-get-set/exercise.js | 8 ++++---- 1-exercises/C-array-get-set/exercises2.js | 2 +- 1-exercises/E-while-loop-with-array/exercise.js | 9 ++++++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..e0034349 100644 --- a/1-exercises/B-array-literals/exercise.js +++ b/1-exercises/B-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -let numbers = []; // add numbers from 1 to 10 into this array -let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +let numbers = [1,2,3,4,5,6,7,8,9,10]; // add numbers from 1 to 10 into this array +let mentors; [ "Daniel", "Irina", "Irina"]// Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/C-array-get-set/exercise.js b/1-exercises/C-array-get-set/exercise.js index 5ca911d5..672aa87e 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -4,12 +4,12 @@ Complete the functions below to get the first and last values from the array */ -function first(arr) { - return; // complete this statement +function first( numbers) { + return [0] [2]; // complete this statement } -function last(arr) { - return; // complete this statement +function last(names) { + return[3]; // complete this statement } /* diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index a8cc3c29..caf5aaff 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,7 +7,7 @@ */ let numbers = [2, 3, 4]; // Don't change this array literal declaration - + numbers[0] = 1; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..5f5cc3c9 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -15,9 +15,16 @@ const BIRTHDAYS = [ "September 28th", "November 15th" ]; +let count = 0; function findFirstJulyBDay(birthdays) { // TODO -} + let i = 0; + while(i < birthdays.length){ + if(birthdays[i].startsWith('July')){ + return birthdays[i]; + } + } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" +} From 321ff7fe5912db2232af7bacd4ff7846bed66515 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:24:50 +0000 Subject: [PATCH 4/9] Update 1-weather-report.js update --- 2-mandatory/1-weather-report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index ebf033c5..72b96332 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -18,7 +18,7 @@ function getTemperatureReport(cities) { let cityDegree = ""; for (let i = 0; i < cities.length; i++) { degree = temperatureService(cities[i]); - cityDegree = `The temperature in ${cities[i]} is ${degree} degrees`; + arr.push(cityDegree); } return arr; From e5b07efadb37bdbb1f2309fcd26d96fef493d238 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:37:36 +0000 Subject: [PATCH 5/9] update mandatory1 --- 2-mandatory/1-weather-report.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 72b96332..5733adac 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -23,9 +23,14 @@ function getTemperatureReport(cities) { } return arr; -} - - +} let arr = []; + let degree = 0; + let cityDegree = ""; + for (let i = 0; i < cities.length; i++) { + degree = temperatureService(cities[i]); + arr.push(cityDegree); + } + return arr /* ======= TESTS - DO NOT MODIFY ===== */ function temperatureService(city) { From 5cc3d9b9133b9b4fd858c1ff2ab7748c07658622 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:46:11 +0000 Subject: [PATCH 6/9] update mandatory-2 --- 2-mandatory/2-financial-times.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index a8b92947..0d3c1eb4 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -29,11 +29,11 @@ function titleWithFewestWords(allArticleTitles) { const myArray = []; for (let article of allArticleTitles) { myArray.push(article.split(" ")); - } //newArray takes individual words are elements - let result = myArray.reduce(function (a, b) { - return a.length <= b.length ? a : b; //compares length of arrays in newArray -> how many words in each array & assigns shortest array to the variable result + } + let result = myArray.reduce(function () { + return a.length <= b.length ? a : b; }); - return allArticleTitles[myArray.indexOf(result)]; //myArray.indexOf(result) -> returns index of result in newArray, which is the same index in allArticleTitles -> returns the title. + return allArticleTitles[myArray.indexOf(result)]; } /* From e1478f89a40c13dec4d91363313e6eb9d3f4a0c7 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:36:14 +0000 Subject: [PATCH 7/9] Update 2-financial-times.js update --- 2-mandatory/2-financial-times.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 0d3c1eb4..8e972be7 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -30,7 +30,7 @@ function titleWithFewestWords(allArticleTitles) { for (let article of allArticleTitles) { myArray.push(article.split(" ")); } - let result = myArray.reduce(function () { + let result = myArray.reduce(function (a,b) { return a.length <= b.length ? a : b; }); return allArticleTitles[myArray.indexOf(result)]; From 90fda6778b99d9777e1c69a089ec63ff4295240e Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:41:31 +0000 Subject: [PATCH 8/9] 2-mandatory/1-weather-report.js update --- 2-mandatory/1-weather-report.js | 1 + 1 file changed, 1 insertion(+) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 5733adac..4d13ce82 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -28,6 +28,7 @@ function getTemperatureReport(cities) { let cityDegree = ""; for (let i = 0; i < cities.length; i++) { degree = temperatureService(cities[i]); + cityDegree = `The temperature in ${cities[i]} is ${degree} degrees`; arr.push(cityDegree); } return arr From faf37a3e7068883486276a8a5f51dad281e89d09 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:04:49 +0000 Subject: [PATCH 9/9] E-while-loop-with-array/exercise.js update --- 1-exercises/E-while-loop-with-array/exercise.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index 5f5cc3c9..97a31ee7 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -15,16 +15,19 @@ const BIRTHDAYS = [ "September 28th", "November 15th" ]; -let count = 0; +//let count = 0; -function findFirstJulyBDay(birthdays) { +function findFirstJulyBDay(parameter) { // TODO - let i = 0; - while(i < birthdays.length){ - if(birthdays[i].startsWith('July')){ - return birthdays[i]; + //let i = 0; + let currentIndex = 0; + while(currentIndex < parameter.length){ + if(parameter[currentIndex].includes('July')){ + return parameter[currentIndex]; } + console.log(parameter[currentIndex]) + currentIndex++; } -console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" + // should output "July 11th" }