London -10/Anu Thapaliya/JS-Core 1-Week3/exercises and mandatory done - #252
London -10/Anu Thapaliya/JS-Core 1-Week3/exercises and mandatory done#252anuthapaliy wants to merge 1 commit into
Conversation
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| forecast = [] |
There was a problem hiding this comment.
it looks like the result is going to be "underfind". You need ro use special wording to declare a variable.
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| forecast = [] | ||
| for(city of cities){ |
There was a problem hiding this comment.
same is here, "city" is not declared yet
|
|
||
| } | ||
| return titleCharacters; | ||
| } |
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| function findingNumber (str){ | ||
| return /[0-9]/.test(str); |
| return titleWithNumbers; | ||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
I think it is better have function separately, not one inside another, so you can use them any time.
|
|
||
| for(let types of closingPricesForAllStocks){ | ||
| let total = 0; | ||
| let average = 0; |
There was a problem hiding this comment.
maybe it would be better to declare "average" variable outside the "for" function, as it is not used inside it, but outside
| let firstDayPrice = types[0]; | ||
| let lastDayPrice = types[types.length-1]; | ||
|
|
||
| changesInPrice.push(Math.round((lastDayPrice - firstDayPrice)*100)/100); |
There was a problem hiding this comment.
why do we need here to multiply and the then divide by 100?
There was a problem hiding this comment.
Multiplying by 100, using Math.round, and then dividing by 100 is one way to round a number to 2 decimal places in JavaScript. This page goes over a couple of ways you can round a number to 2 decimal places: https://linuxhint.com/round-number-to-2-decimal-places-javascript/
| @@ -12,8 +13,19 @@ | |||
| */ | |||
|
|
|||
| function getTemperatureReport(cities) { | |||
There was a problem hiding this comment.
This implementation looks good 👍
As mentioned below, you may just need to check that you're using let or const when declaring a new variable. Even though the code works without it, it's a good habit to get into - otherwise we'll run into problems when we work with larger code bases 😄
| Implement the function below, which returns the title with the fewest words. | ||
| (you can assume words will always be seperated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { |
There was a problem hiding this comment.
This looks almost perfect to me! A couple of very minor points:
- Are you happy with the variable name
shortHeadlines? Maybe think about what value this variable is holding - can you think of a better name for it? - It's a good idea to keep an eye on indentation and spacing - this will make it easier for other developers to read your code. Can you see any indentation in this function that could be improved? 😄
| function headlinesWithNumbers(allArticleTitles){ | ||
| let titleWithNumbers = []; | ||
| for (let headline of allArticleTitles) { | ||
| if (findingNumber(headline)=== true){ |
There was a problem hiding this comment.
When you have an if statement that looks like this: if (findingNumber(headline)=== true){, you can usually re-write it to be if (findingNumber(headline)){.
Can you think of why that works?
| @@ -34,8 +34,25 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |||
| Functions can help with this! | |||
| */ | |||
There was a problem hiding this comment.
This looks good to me - great job 👍
|
Great job on this coursework @anuthapaliy |
No description provided.