London-10-Elena-Barker_ JavaScript-Core-1-Coursework-Week3 - #251
London-10-Elena-Barker_ JavaScript-Core-1-Coursework-Week3#251ElenaBarker wants to merge 3 commits into
Conversation
weather report and financial times done
| output.push (string); | ||
|
|
||
| } | ||
| return output; |
There was a problem hiding this comment.
Comment: Well done!
Consider: You could also use iterate variable as below.
function getTemperatureReport(cities) {
const temperatureReport = [];
for(let i = 0; i < cities.length; i++) {
const temperature = temperatureService(cities[i]);
temperatureReport.push(The temperature in ${cities[i]} is ${temperature} degrees);
}
return temperatureReport;
}
| allTitles.push(headline) | ||
| } | ||
| } | ||
| return allTitles; |
|
|
||
| return shortestLine; | ||
|
|
||
| } |
There was a problem hiding this comment.
Comment: I see you use 100000; as a value. I assume it is a made up value.
Consider: Have a look at how you can use [i] It is not used in any of your coding.
Example:
function titleWithFewestWords(allArticleTitles) {
let shortestTitle = allArticleTitles[0];
for (let i = 1; i < allArticleTitles.length; i++) {
let currentTitle = allArticleTitles[i];
if (currentTitle.length < shortestTitle.length) {
shortestTitle = currentTitle
}
}
return shortestTitle;
}
| } | ||
| } | ||
| return arrayWithNumbers; | ||
|
|
There was a problem hiding this comment.
Comment: I see you use parseInt. Nice. Different solution to mine
| totalCharacters = totalCharacters + headline.length; | ||
| } | ||
| return Math.round(totalCharacters / allArticleTitles.length); | ||
| } |
task finished with all tests passed
all done
| @@ -12,7 +12,15 @@ | |||
| */ | |||
|
|
|||
There was a problem hiding this comment.
This looks good 👍
One suggestion - it's a good idea to use let or const when declaring variables. This code will still work without it, but when you start working on larger programs - you could run into problems.
| @@ -5,7 +5,13 @@ | |||
| Implement the function below, which will return a new array containing only article titles which will fit. | |||
| */ | |||
There was a problem hiding this comment.
Almost perfect - but same comment as above about using let or const 😄
For an extra challenge, try re-writing the below function using the filter array method.
| Implement the function below to return a new array containing all the headlines which contain a number. | ||
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
|
|
There was a problem hiding this comment.
Very nice solution!
I like that you've used a separate function to check if the string has a number. It makes the code very easy to read 👍
| @@ -34,7 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |||
| Functions can help with this! | |||
| */ | |||
There was a problem hiding this comment.
Great job!
Now that you have something that works - maybe you could split some of the code into a separate function improve readability. For example, you could have a function which just calculates the average price given the stockPricesLastFiveDays array.
|
Great work on this coursework @ElenaBarker! Those stocks exercises are tough - you had some really nice solutions 😄 |
weather report and financial times done