Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Glasgow 6_Cat Smith_JS1_Week3 #272

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;


}


Expand Down
9 changes: 8 additions & 1 deletion 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

/*
Expand Down
32 changes: 29 additions & 3 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand All @@ -48,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 ))

}
}

/*
Expand All @@ -64,7 +82,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;
}


Expand Down