JavaScript-core-1-Coursework-week3 Ebrahim Beiati-Asl - #188
Conversation
|
perfect code, nice |
JDysiewicz
left a comment
There was a problem hiding this comment.
Overall really good, well done @ebrahimbeiati :)
| while (i<=n){ | ||
| if(i%2==0) | ||
| i++; | ||
|
|
||
| } | ||
| } |
There was a problem hiding this comment.
Right idea, but you've created an infinite loop here (while i<=n but you only increment i if i%2===0, so when it reaches i=1 you infinitely loop.
What you need is two variables; one to increment on every iteration up to n, and one hold the even numbers
const evenNums = []
let i = 0
while (evenNums.length < n) {
if(i % 2 === 0) {
evenNums.push(i)
}
i++
}
return evenNums
| // TODO | ||
| let i = 0; | ||
| while (i < birthdays.length) { | ||
| if (birthdays[i].includes("July")) return birthdays[i]; |
There was a problem hiding this comment.
is all good, but try to make sure to include {} for if statements, even if they're one line (keeps things consistent)
|
|
||
| do { | ||
| if (counter % 2 === 0) { | ||
| sum = sum + counter; |
There was a problem hiding this comment.
this can be cleaned up by using the += operator; sum += counter
| let temparatureMap = new Map(); | ||
|
|
||
| temparatureMap.set('London', 10); | ||
| temparatureMap.set('Paris', 12); | ||
| temparatureMap.set('Barcelona', 17); | ||
| temparatureMap.set('Dubai', 27); | ||
| temparatureMap.set('Mumbai', 29); | ||
| temparatureMap.set('São Paulo', 23); | ||
| temparatureMap.set('Lagos', 33); | ||
| return temparatureMap.get(city); | ||
| let temparatureMap = new Map(); | ||
|
|
||
| temparatureMap.set("London", 10); | ||
| temparatureMap.set("Paris", 12); | ||
| temparatureMap.set("Barcelona", 17); | ||
| temparatureMap.set("Dubai", 27); | ||
| temparatureMap.set("Mumbai", 29); | ||
| temparatureMap.set("São Paulo", 23); | ||
| temparatureMap.set("Lagos", 33); | ||
|
|
||
| return temparatureMap.get(city); |
There was a problem hiding this comment.
think your formatter settings conflict with the repo here ; is not a huge deal but something to watch out for
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
|
|
||
| return allArticleTitles.filter(items=> items.length < 65); |
There was a problem hiding this comment.
nice use of an arrow function! although to be a bit cleaner the items parameter should probable be called title instead
| for (let price of newPrice) { | ||
| sum += price; | ||
| } | ||
| const average = sum / newPrice.length; |
There was a problem hiding this comment.
what if newPrice is an empty array?
| function factorial(input) { | ||
| let sum = 1; | ||
| for (i = 1; i <= input; i++) { | ||
| sum *= i; | ||
| } | ||
| return sum; | ||
| // TODO |
There was a problem hiding this comment.
good to see you doing the extra ones! :)
Please review my homework and tell me if you see any mistake.