Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

NW Class 5 - Mohammed Alhallaq- Javascript - Core1-Week3 - #138

Open
mhallaq wants to merge 2 commits into
CodeYourFuture:mainfrom
mhallaq:main
Open

NW Class 5 - Mohammed Alhallaq- Javascript - Core1-Week3#138
mhallaq wants to merge 2 commits into
CodeYourFuture:mainfrom
mhallaq:main

Conversation

@mhallaq

@mhallaq mhallaq commented Sep 23, 2022

Copy link
Copy Markdown

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?

let a;
console.log(a);

// this is undefined because it's null , ( contains no value )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
  }
]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tom for this clear elaborated explaination. :-)

let count = 0;
let sum = 0;
do {
if (!(count % 2)) sum = sum + count;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulus. Nice 😁

Comment on lines +14 to 44
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];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you don't need the index (i) for your output here, you could use a for of loop instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thank you.

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
// TODO - implement using a do-while loop
let randomNumber;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Simple and concise 👌

let articleIndex = 0;
let resultArticle = [];
for (i = 0; i < allArticleTitles.length; i++) {
if (pattern.test(allArticleTitles[i])) {

@yogaraptor yogaraptor Sep 27, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, you can use for of here for conciseness

Comment thread 2-mandatory/4-stocks.js
changeInPrice = Number(changeInPrice.toFixed(2));
stockPricesChange[i] = changeInPrice;
}
console.log(stockPricesChange, "----------------------> stockPricesChange");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove console.log statements when done if they're just for debugging 👌

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, I forgot to clean it out; thanks for your thorough review. :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants