-
-
Notifications
You must be signed in to change notification settings - Fork 283
London10-Afsha-Hossain-JS-Core1-Coursework-Week3 #257
base: main
Are you sure you want to change the base?
Conversation
Answered using comments why the outputs in the exercises are undefined
function titleWithFewestWords(allArticleTitles) { | ||
let shortestHeadline; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could declare 'shortestHeadline' with const keyword instead let
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think shortestHeadline
needs to be declared with let
here as we are re-assigning a new value to it a few lines later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
@@ -12,6 +12,12 @@ | |||
*/ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect 👍
@@ -5,6 +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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look good!
For extra practice, can you try re-writing this using the filter
array method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
|
||
// The output in the example below contains undefined because letters is an array with three elements, indexed from 0 to 2. | ||
// When we try to access the element at index 3 (arr[3]), which is beyond the last index of the letters array, JavaScript returns undefined because there is no value at that index. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice explanation.
if (BIRTHDAYS[i].startsWith("July")) | ||
return BIRTHDAYS[i]; | ||
i++; | ||
} | ||
} | ||
|
||
console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, consice and good.
@@ -13,25 +20,72 @@ function potentialHeadlines(allArticleTitles) { | |||
Implement the function below, which returns the title with the fewest words. | |||
(you can assume words will always be seperated by a space) | |||
*/ | |||
// ["The", "three", "questions", "that", "dominate", "investment"] | |||
// fewestNumberOfWords = articleSplitter.length; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good attempt 👍 One small improvement:
- Could you try doing this without using
let fewestNumberOfWords = 1000;
- You could either leave it uninitialised and check for
undefined
in your loop.. Or you could maybe initialise to the numberOfWords of the first title in the list.
// 1. We are getting array of string. We need to find if the string includes numbers. | ||
// 2. Once we find a number, we will put the string to the new array. | ||
// 3. We are going to return the new array. New array is string with numbers. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍
// 2. We need to find the number of Article titles. | ||
// 3. We divide (total character) by (number of article titles). | ||
// 4. Round it up | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good!
// 2. Divide the total price by the number of days i.e. 5 | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good variable names 😄
One question: Do you need to re-calculate the average each time through the loop? Maybe it's enough to just calculate the average once at the end?
@@ -48,7 +64,13 @@ function getAveragePrices(closingPricesForAllStocks) { | |||
The price change value should be rounded to 2 decimal places, and should be a number (not a string) | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
One question: Will this code - closingPricesEachcompany[4] - closingPricesEachcompany[0]
- still work if we have more than 5 prices in each array? Or less than 5 prices?
Can you think of how to make sure this works for any numbers of prices?
// } | ||
// } | ||
// arrayWithHighestValue.push(highestPrice); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a tough one!
Well done for completing it 👏
Great job on this coursework 👏 |
Thank you for your consideration and comments. I am going to apple what have you recommended me regarding some exercises. |
We checked if we have an array that is the same length as the number of cities passed in.
No description provided.