From a6d53cb0f3b77b41741366412ddab1fb8cbbe10f Mon Sep 17 00:00:00 2001 From: CatSmith1 <105733850+CatSmith1@users.noreply.github.com> Date: Sat, 4 Mar 2023 17:02:52 +0000 Subject: [PATCH 1/2] weather rep and stocks 1&3 --- 2-mandatory/1-weather-report.js | 11 ++++++++++- 2-mandatory/3-stocks.js | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..2f044627 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,7 +12,16 @@ */ function getTemperatureReport(cities) { - // TODO +const statements = []; + for (const city of cities) { + let degrees= temperatureService(city); + let statement= ("The temperature in " + city + " is " + degrees + " degrees "); + statements.push(statement) + +} +return statements; + + } diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..ef8be1f7 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,7 +34,17 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + const averagePrices = []; + for (const closingPrices of closingPricesForAllStocks){ + let sum =0; + for (const closingPrice of closingPrices) { + sum += closingPrice; + } + averagePrices.push (Math.round (sum / closingPrices.length * 100) /100); + + + } + return averagePrices } /* @@ -64,7 +74,15 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO + const descriptions =[]; + for (let index = 0; index < closingPricesForAllStocks.length; index++) { + + const closingPrices =closingPricesForAllStocks [index]; + const maxPrice =Math.max(...closingPrices).toFixed(2); + + descriptions.push (`The highest price of ${stocks[index].toUpperCase()} in the last 5 days was ${maxPrice}`); +} +return descriptions; } From 25d37f7788546e6d83ae7d7ca861da0b7687a2f7 Mon Sep 17 00:00:00 2001 From: CatSmith1 <105733850+CatSmith1@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:04:49 +0000 Subject: [PATCH 2/2] work on task 2 and 3 --- 2-mandatory/2-financial-times.js | 9 ++++++++- 2-mandatory/3-stocks.js | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..6289031e 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,7 +5,14 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + return allArticleTitles.length <= 65; + + let shortHeadlines =[]; + for (const articleTitles of allArticleTitles){ + if (potentialHeadlines.length <= 65) { + shortHeadlines.push(allArticleTitles) + } + } } /* diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index ef8be1f7..c8da4c55 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -58,7 +58,15 @@ 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 priceChanges of closingPricesForAllStocks){ + let sum =0; + for (const priceChange of priceChanges) { + sum += priceChange + } + priceChanges.push (Math.round(sum )) + + } } /*