From f82b563e1892760764aba3932bc3cb39cf08e989 Mon Sep 17 00:00:00 2001 From: Hussein Date: Sun, 5 Mar 2023 19:27:29 +0000 Subject: [PATCH 01/14] mandadory 1 solved --- 2-mandatory/1-weather-report.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..65bc5c7d 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,7 +12,15 @@ */ function getTemperatureReport(cities) { - // TODO + const citiesReport = []; + + for (const city of cities){ + let cityTemparature = temperatureService(city); + let statement = `The temperature in ${city} is ${cityTemparature} degrees`; + + citiesReport.push(statement); + } +return citiesReport; } From ab32560a75fe45548d60856277224d4dd625b580 Mon Sep 17 00:00:00 2001 From: Hussein Date: Sun, 5 Mar 2023 19:28:38 +0000 Subject: [PATCH 02/14] task 1 of mandatory 2 solved --- 2-mandatory/2-financial-times.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..60e48ec3 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,7 +5,15 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + + let fittingArticles = []; + + for (const title of allArticleTitles) { + if (title.length <= 65){ + fittingArticles.push(title); + } + } + return fittingArticles; } /* From 6f50b2c8597d937e9712025836620f99bc425d01 Mon Sep 17 00:00:00 2001 From: Hussein Date: Sun, 5 Mar 2023 21:09:53 +0000 Subject: [PATCH 03/14] mandatory 2 completed --- 2-mandatory/2-financial-times.js | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 60e48ec3..7e76afab 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -22,7 +22,13 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + let shortestTitle = allArticleTitles[1]; + for (const newTitle of allArticleTitles){ + if (newTitle.length <= shortestTitle.length){ + shortestTitle = newTitle; + } + } + return shortestTitle; } /* @@ -31,7 +37,18 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO + let clickables = []; + + for (const title of allArticleTitles){ + for (const character of title){ + if ('0123456789'.includes(character)){ //if (character = Number) my previous -failed- solution. + clickables.push(title); + break; + } + + } + } + return clickables; } /* @@ -39,7 +56,20 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - // TODO + let charactersCount= 0; + let titlesCount= 0; + + for (const title of allArticleTitles){ + for (const part of title){ + for (const character of part){ + charactersCount = charactersCount + 1; + } + } + titlesCount = titlesCount + 1; + } + + let average = charactersCount / titlesCount; + return Math.round(average); } From 9e5e2f53e3f19b33887686208ab53e73221a33cb Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 00:17:39 +0000 Subject: [PATCH 04/14] mand3 task1 --- 2-mandatory/3-stocks.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..65cb4660 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,7 +34,19 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + let averagePrices = []; + + for (const stock of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){ + let pricesTotal = 0; + for (const prices of stock){ + pricesTotal += prices; + } + let averagePrice = Number((pricesTotal / stock.length).toFixed(2)); + averagePrices.push(averagePrice); + } + + + return averagePrices; } /* From e1fbcd39b5591f9ed58447d2789309687f5d6219 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 00:28:55 +0000 Subject: [PATCH 05/14] mand3 task 2 from 1st try B-) --- 2-mandatory/3-stocks.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 65cb4660..123eae78 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -60,7 +60,13 @@ function getAveragePrices(closingPricesForAllStocks) { The price change value should be rounded to 2 decimal places, and should be a number (not a string) */ function getPriceChanges(closingPricesForAllStocks) { - // TODO + const priceChanges = []; + + for (const stock of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){ + let priceChange = Number((stock[4] - stock[0]).toFixed(2)); + priceChanges.push(priceChange); + } + return priceChanges; } /* From 5da1be33804125e9d894f34ede322657ec86a199 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 00:49:39 +0000 Subject: [PATCH 06/14] mand3 task 3 1st attempt --- 2-mandatory/3-stocks.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 123eae78..4f70fb11 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -82,7 +82,22 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO + const highestPricereports = []; + + for (const stock of stocks){ + let highestPrice = 0; + + for (const price of stock){ + + if (price > 0){ + highestPrice = price; + } + } + highestPrice = Number(highestPrice.toFixed(2)); + highestPricereports.push(`The highest price of ${toUpperCase(stock)} in the last 5 days was ${highestPrice}`); + } + + return highestPricereports; } From 195b15c5329c0b7c955a34ca6ff5dc40ae0978ef Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 00:56:39 +0000 Subject: [PATCH 07/14] mand3 task3 2nd attempt --- 2-mandatory/3-stocks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 4f70fb11..e2e02c1c 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -82,22 +82,22 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - const highestPricereports = []; + const highestPriceReports = []; for (const stock of stocks){ let highestPrice = 0; for (const price of stock){ - if (price > 0){ + if (price > highestPrice){ highestPrice = price; } } - highestPrice = Number(highestPrice.toFixed(2)); - highestPricereports.push(`The highest price of ${toUpperCase(stock)} in the last 5 days was ${highestPrice}`); + //highestPrice = Number(highestPrice.toFixed(2)); + highestPriceReports.push(`The highest price of ${toUpperCase(stock)} in the last 5 days was ${highestPrice}`); } - return highestPricereports; + return highestPriceReports; } From 96101ca726fe2016d92f2d6b0edfa8bdf233cdd6 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 03:11:21 +0000 Subject: [PATCH 08/14] few more attempts not solved copletly, but one attempt closer to success. and couple chatgpt fix suggustions, wich neither works but closer to success. --- 2-mandatory/3-stocks.js | 82 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index e2e02c1c..76cd78c4 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -81,24 +81,100 @@ function getPriceChanges(closingPricesForAllStocks) { The stock ticker should be capitalised. The price should be shown with exactly 2 decimal places. */ + function highestPriceDescriptions(closingPricesForAllStocks, stocks) { const highestPriceReports = []; + let stockPrices = CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[0]; for (const stock of stocks){ let highestPrice = 0; + + for (const price of stockPrices){ - for (const price of stock){ + if (price > highestPrice){ + highestPrice = price; + } + + } + + highestPrice = Number(highestPrice.toFixed(2)); + highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); + //stockPrices = CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[0++]; (not working) + //(trying to update the prices array that coresponds to the new stock) + } + + return highestPriceReports; +} + +/*dead end attempt +function highestPriceDescriptions(closingPricesForAllStocks, stocks) { + const highestPriceReports = []; + + + for (const stockPrices of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){ + let highestPrice = 0; + + for (const price of stockPrices){ if (price > highestPrice){ highestPrice = price; } + } - //highestPrice = Number(highestPrice.toFixed(2)); - highestPriceReports.push(`The highest price of ${toUpperCase(stock)} in the last 5 days was ${highestPrice}`); + + highestPrice = Number(highestPrice.toFixed(2)); + highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); } return highestPriceReports; +}*/ + +/*chtgpt suggested fix. works for all stocks except last one, prints with only one decimal place! +function highestPriceDescriptions(closingPricesForAllStocks, stocks) { + const highestPriceReports = []; + + for (const stockIndex in closingPricesForAllStocks) { + const stockPrices = closingPricesForAllStocks[stockIndex]; + const stock = stocks[stockIndex].toUpperCase(); + let highestPrice = 0; + + for (const price of stockPrices) { + if (price > highestPrice) { + highestPrice = price; + } + } + + highestPrice = Number(highestPrice.toFixed(2)); + highestPriceReports.push(`The highest price of ${stock} in the last 5 days was ${highestPrice}`); + } + + return highestPriceReports; } +*/ + +/*another chtgpt suggested fix. repeats 1st value twice for some reason! +function highestPriceDescriptions(closingPricesForAllStocks, stocks) { + const highestPriceReports = []; + let stockPrices = closingPricesForAllStocks[0]; + + for (const stock of stocks){ + let highestPrice = 0; + + for (const price of stockPrices){ + + if (price > highestPrice){ + highestPrice = price; + } + + } + + highestPrice = highestPrice.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); + highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); + stockPrices = closingPricesForAllStocks.shift(); + } + + return highestPriceReports; +}*/ /* ======= TESTS - DO NOT MODIFY ===== */ From 527c5c1cd481de6426348ef00e66b0912060fc70 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 21:30:20 +0000 Subject: [PATCH 09/14] linking worked, decimal issues stocks array elements linked to their coresponding price array seccussfully. little issue however, last string's highest price orints only with onw decimal place! --- 2-mandatory/3-stocks.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 76cd78c4..55bdbabb 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -84,10 +84,12 @@ function getPriceChanges(closingPricesForAllStocks) { function highestPriceDescriptions(closingPricesForAllStocks, stocks) { const highestPriceReports = []; - let stockPrices = CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[0]; + let pricesArray = 0; + for (const stock of stocks){ let highestPrice = 0; + let stockPrices = CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[pricesArray]; for (const price of stockPrices){ @@ -99,8 +101,9 @@ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { highestPrice = Number(highestPrice.toFixed(2)); highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); - //stockPrices = CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[0++]; (not working) - //(trying to update the prices array that coresponds to the new stock) + pricesArray++; + //(trying to update the prices array that coresponds to the new stock) + //(upon an advice from Greg, I added a variable that increments every time through and assigned this variable as the arrary element index) } return highestPriceReports; From edcd64e1454488256401fb3462b75d2070dbfd26 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 6 Mar 2023 21:43:14 +0000 Subject: [PATCH 10/14] cleared up from etra comments --- 2-mandatory/3-stocks.js | 71 ----------------------------------------- 1 file changed, 71 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 55bdbabb..07c057d3 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -102,82 +102,11 @@ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { highestPrice = Number(highestPrice.toFixed(2)); highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); pricesArray++; - //(trying to update the prices array that coresponds to the new stock) - //(upon an advice from Greg, I added a variable that increments every time through and assigned this variable as the arrary element index) - } - - return highestPriceReports; -} - -/*dead end attempt -function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - const highestPriceReports = []; - - - for (const stockPrices of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){ - let highestPrice = 0; - for (const price of stockPrices){ - - if (price > highestPrice){ - highestPrice = price; - } - - } - - highestPrice = Number(highestPrice.toFixed(2)); - highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); } return highestPriceReports; -}*/ - -/*chtgpt suggested fix. works for all stocks except last one, prints with only one decimal place! -function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - const highestPriceReports = []; - - for (const stockIndex in closingPricesForAllStocks) { - const stockPrices = closingPricesForAllStocks[stockIndex]; - const stock = stocks[stockIndex].toUpperCase(); - let highestPrice = 0; - - for (const price of stockPrices) { - if (price > highestPrice) { - highestPrice = price; - } - } - - highestPrice = Number(highestPrice.toFixed(2)); - highestPriceReports.push(`The highest price of ${stock} in the last 5 days was ${highestPrice}`); - } - - return highestPriceReports; } -*/ - -/*another chtgpt suggested fix. repeats 1st value twice for some reason! -function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - const highestPriceReports = []; - let stockPrices = closingPricesForAllStocks[0]; - - for (const stock of stocks){ - let highestPrice = 0; - - for (const price of stockPrices){ - - if (price > highestPrice){ - highestPrice = price; - } - - } - - highestPrice = highestPrice.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); - highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); - stockPrices = closingPricesForAllStocks.shift(); - } - - return highestPriceReports; -}*/ /* ======= TESTS - DO NOT MODIFY ===== */ From 1efeab2b14a613a04fc2b60c9073d78d9f5a7896 Mon Sep 17 00:00:00 2001 From: Hussein Al-Sayed <111397062+hussein-alsayed@users.noreply.github.com> Date: Tue, 7 Mar 2023 00:38:40 +0000 Subject: [PATCH 11/14] Update 2-mandatory/2-financial-times.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zsolt Sz. Sztupák --- 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 7e76afab..98559a8f 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -56,7 +56,7 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - let charactersCount= 0; + let charactersCount = 0; let titlesCount= 0; for (const title of allArticleTitles){ From 8b64044a315d55b91ff30d3fcb86b84f9cc65f75 Mon Sep 17 00:00:00 2001 From: Hussein Date: Tue, 7 Mar 2023 00:52:18 +0000 Subject: [PATCH 12/14] minor identation fixes, and couple exercise solution updates --- 2-mandatory/1-weather-report.js | 2 +- 2-mandatory/2-financial-times.js | 18 +++++++++--------- 2-mandatory/3-stocks.js | 9 ++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 65bc5c7d..0acd0289 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -20,7 +20,7 @@ function getTemperatureReport(cities) { citiesReport.push(statement); } -return citiesReport; + return citiesReport; } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 98559a8f..81d91f58 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -22,7 +22,7 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - let shortestTitle = allArticleTitles[1]; + let shortestTitle = allArticleTitles[0]; for (const newTitle of allArticleTitles){ if (newTitle.length <= shortestTitle.length){ shortestTitle = newTitle; @@ -56,16 +56,17 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - let charactersCount = 0; - let titlesCount= 0; + let charactersCount= 0; + let titlesCount = 0; for (const title of allArticleTitles){ - for (const part of title){ - for (const character of part){ - charactersCount = charactersCount + 1; - } + + if (title.length > 0){ + charactersCount += title.length; + } - titlesCount = titlesCount + 1; + + titlesCount++; } let average = charactersCount / titlesCount; @@ -73,7 +74,6 @@ function averageNumberOfCharacters(allArticleTitles) { } - /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ "Streaming wars drive media groups to spend more than $100bn on new content", diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 07c057d3..f18ce932 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -38,11 +38,14 @@ function getAveragePrices(closingPricesForAllStocks) { for (const stock of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){ let pricesTotal = 0; + for (const prices of stock){ - pricesTotal += prices; + + pricesTotal += prices; } - let averagePrice = Number((pricesTotal / stock.length).toFixed(2)); - averagePrices.push(averagePrice); + + let averagePrice = Number((pricesTotal / stock.length).toFixed(2)); + averagePrices.push(averagePrice); } From 6e209d8ba694fbfed02ea01b97323e8b047560eb Mon Sep 17 00:00:00 2001 From: Hussein Date: Thu, 9 Mar 2023 00:21:16 +0000 Subject: [PATCH 13/14] decimal place issue fixed --- 2-mandatory/3-stocks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index f18ce932..330b7d33 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -102,8 +102,8 @@ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { } - highestPrice = Number(highestPrice.toFixed(2)); - highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); + // highestPrice = Number(highestPrice.toFixed(2)); + highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice.toFixed(2)}`); pricesArray++; } From 66c47e72058f1dd50471d10b4b6df6c05d64efc2 Mon Sep 17 00:00:00 2001 From: Hussein Date: Thu, 9 Mar 2023 00:21:48 +0000 Subject: [PATCH 14/14] comment added --- 2-mandatory/3-stocks.js | 1 + 1 file changed, 1 insertion(+) diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 330b7d33..71b36ce6 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -103,6 +103,7 @@ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { } // highestPrice = Number(highestPrice.toFixed(2)); + //(Number object switchh the value from "string" to numbers, which don't see the onely zero at the decimal place as a number then). highestPriceReports.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice.toFixed(2)}`); pricesArray++;