NW6 | Nazanin Saedi | object-destructuring | Module-JS3 | Exercise 3 | Week 3#322
NW6 | Nazanin Saedi | object-destructuring | Module-JS3 | Exercise 3 | Week 3#322nazaninsaedi wants to merge 15 commits intoCodeYourFuture:mainfrom
Conversation
NW6 | NazaninSaedi | BookLibrary-JS3 | Week-1
|
| author.value == "" || | ||
| pages.value == null || | ||
| pages.value == "" | ||
| ) { |
There was a problem hiding this comment.
Nazanin, I would suggest instead of explicitly checking for null/empty string here, use falsy check like this:
if (!title.value || ! author.value || !pages.value) { ... }
This way JavaScript will check for null/undefined/empty string for you.
There was a problem hiding this comment.
If you want to check for some value, please, consider using === instead of ==. This way JS will check for the value and for the type.
| // } | ||
|
|
||
| // introduceYourself(personOne); | ||
| function introduceYourself({ name, age, favouriteFood }) { |
There was a problem hiding this comment.
Please, avoid having commented out code in your PRs. I would just delete the block, but if I know that I might need it in the future, I would write down previous commit hash for the reference.
| let GryffindorMembers = hogwarts.filter(({ house }) => house === "Gryffindor"); | ||
| GryffindorMembers.forEach(({ firstName, lastName }) => { | ||
| console.log('${firstName} ${lastName}'); | ||
| }); |
There was a problem hiding this comment.
Please, us back ticks (`) here like this:
console.log(`${firstName} ${lastName}`);
| //Task 2 | ||
| console.log("Task 2:"); | ||
| let teachersWithPets = hogwaters.filter(({ occupation, pet }) => occupation === "Teacher" && pet !== null); | ||
| teachersWithPets.forEach(({ firstName, lastName }) => { |
There was a problem hiding this comment.
It is just a matter of coding style, but I prefer to put constants to the left in the comparisons, like this:
"Teacher" === occupation
The reason is that if you will try to make a silly mistake like this:
"Teacher" = occupation
JS will not compile and throw an error. Because you can't assign a new value to a constant. While in case of occupation = "Teacher" JS will eagerly accept it as valid.
There was a problem hiding this comment.
if you want to check for null only for pet, then you code is ok, but usually people tend to check in general for all falsy values (null/undefined/empty string), in that case a better approach will be:
instead of:
pet !== null
use:
({ occupation, pet }) => "Teacher" === occupation && pet
| async function fetchComic(){ | ||
| try { | ||
| const response = await fetch('https://xkcd.now.sh/?comic=latest'); | ||
| const data = await response.json(); |
There was a problem hiding this comment.
I don't think you need await in front of response.json() here. You already waited for the fetch().
tyzia
left a comment
There was a problem hiding this comment.
Overall looks good. Left some minor comments.




one explanation :
The console.log("QTY\tITEM\t\t\tTOTAL"); line is used to print the header of the receipt, which includes the titles for each column: "QTY" for quantity, "ITEM" for item name, and "TOTAL" for total cost.
Here's a breakdown of what each part of the string does:
\t: This is an escape sequence representing a tab character. It adds spacing between the columns.
"QTY": This is the title for the quantity column.
"ITEM": This is the title for the item name column.
"\t\t\t": This adds extra tabs to provide additional spacing between the item name column and the total column.
"TOTAL": This is the title for the total cost column.