NW Class 5 - Mohammed Alhallaq- Javascript - Core1-Week3 - #138
Conversation
| let a; | ||
| console.log(a); | ||
|
|
||
| // this is undefined because it's null , ( contains no value ) |
There was a problem hiding this comment.
Actually, it's undefined, not null. For something to be null we have to explicitly mark it as such, like this:
let a = null;You would use null when you want to intentionally mark something as empty/missing, e.g. in this list, the singer Cher has no last name - this isn't a mistake, it's just a fact of her name:
const artists = [
{
firstName: 'Ravi',
lastName: 'Shankar',
numberOfSongs: 93
},
{
firstName: 'Cher',
lastName: null,
numberOfSongs: 72
},
{
firstName: 'Miles',
lastName: 'Davis',
numberOfSongs: 89
}
]There was a problem hiding this comment.
Thanks Tom for this clear elaborated explaination. :-)
| let count = 0; | ||
| let sum = 0; | ||
| do { | ||
| if (!(count % 2)) sum = sum + count; |
| let cities = [ | ||
| "London", | ||
| "Paris", | ||
| "Barcelona", | ||
| "Dubai", | ||
| "Mumbai", | ||
| "São Paulo", | ||
| "Lagos", | ||
| ]; | ||
| let citiesTemp = [ | ||
| "London", | ||
| 10, | ||
| "Paris", | ||
| 12, | ||
| "Barcelona", | ||
| 17, | ||
| "Dubai", | ||
| 27, | ||
| "Mumbai", | ||
| 29, | ||
| "São Paulo", | ||
| 23, | ||
| "Lagos", | ||
| 33, | ||
| ]; | ||
|
|
||
| function getTempratur(city) { | ||
| let index = citiesTemp.indexOf(city); | ||
| index++; | ||
| return citiesTemp[index]; | ||
| } |
There was a problem hiding this comment.
This is an interesting approach! I think in some lower-level programming languages, storing info like this (an array with alternating keys and values) might be more common place. In JS, it's more conventional to use a dictionary:
const cityTemperatures = {
"São Paulo": 23,
"Lagos": 33
}or a Map as used by the function the exercise provides below (the exercise suggested you use that function rather than write your own, but nothing wrong with trying things out for yourself 💪 )
| function getTemperatureReport(cities) { | ||
| let tempratureReport = []; | ||
| // TODO | ||
| for (let i = 0; i < cities.length; i++) { |
There was a problem hiding this comment.
Because you don't need the index (i) for your output here, you could use a for of loop instead.
| function getRandomNumberGreaterThan50() { | ||
| // TODO - implement using a do-while loop | ||
| // TODO - implement using a do-while loop | ||
| let randomNumber; |
| let articleIndex = 0; | ||
| let resultArticle = []; | ||
| for (i = 0; i < allArticleTitles.length; i++) { | ||
| if (pattern.test(allArticleTitles[i])) { |
There was a problem hiding this comment.
I think the comment on the function was hinting that you use for of on the titles to iterate through and detect numbers, but a regex is definitely a more efficient solution 👍
| let sumArticleChar = 0; | ||
| let averageNumber; | ||
| let numberOfArticles = allArticleTitles.length; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { |
There was a problem hiding this comment.
Again, you can use for of here for conciseness
| changeInPrice = Number(changeInPrice.toFixed(2)); | ||
| stockPricesChange[i] = changeInPrice; | ||
| } | ||
| console.log(stockPricesChange, "----------------------> stockPricesChange"); |
There was a problem hiding this comment.
Don't forget to remove console.log statements when done if they're just for debugging 👌
There was a problem hiding this comment.
Oh, yeah, I forgot to clean it out; thanks for your thorough review. :-)
Your Details
Your Name: Mohammed Alhallaq
Your City: Manchester
Your Slack Name: Malhallaq
Homework Details
Module: Javasript Core1
Week: 3
Notes
What did you find easy?
most of the exercises
What did you find hard?
the extra challenge of the HW
What do you still not understand?
Nothing
Any other notes?