Skip to content
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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

nazaninsaedi
Copy link

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.

Copy link

sonarqubecloud bot commented May 3, 2024

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

function submit() {
if (
title.value == null ||
title.value == "" ||
author.value == null || // Check for author input
author.value == "" ||
pages.value == null ||
pages.value == ""
) {
Copy link

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.

Copy link

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 }) {
Copy link

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}');
});
Copy link

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 }) => {
Copy link

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.

Copy link

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();
Copy link

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().

Copy link

@tyzia tyzia left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants