London Class 8 - Hatice Aydogan- JS Core 1 Coursework - Week 3 - #23
London Class 8 - Hatice Aydogan- JS Core 1 Coursework - Week 3#23Hatice06 wants to merge 3 commits into
Conversation
|
|
||
| // TODO - Write for loop code here | ||
| for(i = 0; i < WRITERS.length; i++){ | ||
| console.log(`${WRITERS[i]} is ${AGES[i]} years old`) |
There was a problem hiding this comment.
great use of interpolation!
| // } else { | ||
| // return acc; | ||
| // } | ||
| // }, ""); |
There was a problem hiding this comment.
Great job! Just one minor detail, it may be best to remove commented out code in order to find the relevant code faster and easier.
ewintram
left a comment
There was a problem hiding this comment.
Super job, well done. It's great to see you using so many array methods already.
| }; | ||
| i++ | ||
| } while (count < n); | ||
| return sum; |
There was a problem hiding this comment.
well done, this was difficult. If you check the solutions you can see how you can do this with only sum and i variables
There was a problem hiding this comment.
Thanks Ellie, I checked the solution and I changed my solution with sum and i variables.
| let currentCity = cities[i]; | ||
| let currentCityTemperature = temperatureService(currentCity); | ||
| cityWithTemperature.push( | ||
| `The temperature in ${currentCity} is ${currentCityTemperature} degrees` |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| let titlesMoreThan65Char = allArticleTitles.filter( |
There was a problem hiding this comment.
great use of filter. You can also do this with a loop but it's great you're practising array methods :)
There was a problem hiding this comment.
Thanks Ellie, I did it with for loop again.
| title.split("").forEach((character) => { | ||
| if (numbers.includes(character)) { | ||
| titlesToReturn.push(title); | ||
| } |
There was a problem hiding this comment.
wow, well done for using string & array methods. You can also do this with for loops, but array methods are more commonly used, so this is excellent work
There was a problem hiding this comment.
Thanks Ellie, we did this together with the TA in the homework club. I tried to do this with loops as a second solution.
| let totalCharacterNumber = 0; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| totalCharacterNumber = | ||
| totalCharacterNumber + allArticleTitles[i].split("").length; |
There was a problem hiding this comment.
remember you can use .length on a string too, so you don't need to split the string
There was a problem hiding this comment.
Thanks Ellie, I removed split.
| // }, ""); | ||
| let shortestTitle = allArticleTitles[0]; | ||
| for (let i = 1; i < allArticleTitles.length; i++) { | ||
| if (allArticleTitles[i].split("").length < shortestTitle.split("").length) { |
There was a problem hiding this comment.
the test for this passes because the title with the shortest number of words is also the title with the fewest characters.
Can you tell what needs to change in order to check which title has the fewest words? Hint: what's the difference between
allArticleTitles[i].split("").length
and
allArticleTitles[i].split(" ").length
There was a problem hiding this comment.
Hi Ellie, the first one takes all the characters of the array as one item, therefore the length of the array is equal to the number of the characters including spaces. The second one is taking all the words in the array as an item, therefore the number of the words is the length of the array. I changed mine to the second one.
| let salesAveragePrices = [] | ||
| for(let i = 0; i <closingPricesForAllStocks.length; i++){ | ||
| let eachCompanySalesTotal = 0; | ||
| for(let j = 0; j < closingPricesForAllStocks[i].length; j++){ |
There was a problem hiding this comment.
well done! This was tough. When you look at the solutions, think about how you can break this down into smaller problems and functions
There was a problem hiding this comment.
Thanks Ellie, I checked the solution document, you are right the solution is clear and easier to understand than mine.
| // TODO | ||
| let highestPriceByCompany = []; | ||
| for( let i = 0; i < closingPricesForAllStocks.length; i++ ){ | ||
| let highestPrice = Math.max(...closingPricesForAllStocks[i]).toFixed(2); |
There was a problem hiding this comment.
wow well done for finding Math.max to make life easier :)
| total = total * i | ||
| } | ||
| return total; | ||
| } |
No description provided.