-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NW6 | Nazanin Saedi | object-destructuring | Module-JS3 | Exercise 3 | Week 3 #322
base: main
Are you sure you want to change the base?
Conversation
NW6 | NazaninSaedi | BookLibrary-JS3 | Week-1
|
function submit() { | ||
if ( | ||
title.value == null || | ||
title.value == "" || | ||
author.value == null || // Check for author input | ||
author.value == "" || | ||
pages.value == null || | ||
pages.value == "" | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need await in front of response.json() here. You already waited for the fetch().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.