London Class 9- Leila Farsani- JavaScript-Core-3-Coursework-Week3 - #163
London Class 9- Leila Farsani- JavaScript-Core-3-Coursework-Week3#163leilafarsani wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Wow! Very impressive @leilafarsani
You've taken to Javascript "like a duck to water" (daft english expression 😆 )
Keep pushing your skills, you have a talent for this 👏
| } | ||
| return even.toString(); | ||
| } | ||
| console.log(evenNumbers()); |
There was a problem hiding this comment.
This logs out the array fine, looks good.
It's a minor point but the instruction is asking to log it out as a comma-separated string. Have a look at the array.join method.
| } | ||
| let i = 0; | ||
| let even = []; | ||
| while (i < 2 * n) { |
| // TODO | ||
| let i = 0; | ||
| while (i < birthdays.length) { | ||
| if (birthdays[i][1] === "u") { |
There was a problem hiding this comment.
This works, but what if later on more birthdays are added to the array including ones in June? Is it a bit more robust and readable to look for the whole word July?
| let i = 0; | ||
| let sum = n * (n - 1); | ||
| do { | ||
| return sum; |
There was a problem hiding this comment.
This is returning instantly from the evenNumbersSum function, so it only ever executes once. Line 12 (let sum) is working out the total on its own, so there's no need for the loop. Is there a way to work out the total by adding to the total on each iteration of the loop?
| // TODO - Write for loop code here | ||
|
|
||
| for (i = 0; i < WRITERS.length; i++) { | ||
| let text = WRITERS[i] + " is " + AGES[i] + " years old"; |
There was a problem hiding this comment.
Great! Also have a look at string templates, see if you prefer that syntax.
| total += closingPricesForAllStocks[i][j]; | ||
| } | ||
| let average = total / closingPricesForAllStocks[i].length; | ||
| let roundedAverage = Number(average.toFixed(2)); |
| // TODO | ||
| let changeArr=[]; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++){ | ||
| let change = closingPricesForAllStocks[i][closingPricesForAllStocks.length - 1] - closingPricesForAllStocks[i][0]; |
There was a problem hiding this comment.
This works 👍
It's a little hard to read, eg could break into separate lines:
const prices = closingPricesForAllStocks[i]
const firstPrice = prices[0]
const lastPrice = prices[prices.length - 1]
const change = lastPrice - firstPrice;
| // TODO | ||
| let maxArray = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++){ | ||
| let maxStocks = Math.max(...closingPricesForAllStocks[i]).toFixed(2); |
There was a problem hiding this comment.
toFixed returns a string, and Math.max expects a list of numbers
| let cookingGenre = []; | ||
| let booksArr = []; | ||
| for (let i = 0; i < books.length; i++) { | ||
| if (books[i].genre === "children") { |
| cookingGenre.push(books[i]); | ||
| } | ||
| } | ||
| let childrenSorted = childrenGenre.sort((a, b) => a.rating - b.rating); |
There was a problem hiding this comment.
Nice! Also consider
const sorted = childrenGenre.sort().reverse()
|
Good Job! |
No description provided.