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

West Midlands | Gabriel Deng | Module-Data-Groups | Week 2 - Book reading #131

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

Conversation

gai93003
Copy link

@gai93003 gai93003 commented Jan 9, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@gai93003 gai93003 added the Needs Review Participant to add when requesting review label Jan 9, 2025
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jan 16, 2025
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

In terms of input validation,

  1. Are all input properly checked?
  2. Can .value be null?
  3. What if a user enters only space characters in the "title" input field?
  4. What if a users enters -1 or 3.1416 in the "pages" input field?

There are also some errors in index.html.

@@ -54,7 +54,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
Copy link

Choose a reason for hiding this comment

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

Can you think of a more efficient way to remove all rows (except the heading) in the table?

Copy link
Author

Choose a reason for hiding this comment

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

I think the most efficient way is to set the innerHTML of the table to emtpy and then appendChild header. In this case the first row.

Copy link
Author

Choose a reason for hiding this comment

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

I have also implemented the checking of the input of spaces using the input.value.trim() and check if it is empty. If so, an alert will pop out. Similarly, the validation of the page input field is also implemented.

delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
Copy link

Choose a reason for hiding this comment

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

  • Do you think the value assigned to this id attribute is unique?
  • Do you think there is a need to assign any id attribute to delButton?
  • Do you think there is a need to assign any id attribute to changeBut (at line 75)?
  • Can you think of a more consistent naming convention for the variables representing the two buttons?

Copy link
Author

Choose a reason for hiding this comment

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

The assignment of the id in this case is not important because there is no where in the code where the button is being used in reference to the id. So i have deleted it to make the code more readable and as precise as possible.

@@ -62,3 +67,8 @@ console.log(y);
```

What will be the output of this code. Explain your answer in 50 words or less.

Ans: The output will be 9 and {x: 10}; This is due to the difference by which each of the
Copy link

Choose a reason for hiding this comment

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

Spot on.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks

@@ -35,6 +38,8 @@ console.log(y);

What will be the output of this code. Explain your answer in 50 words or less.

Ans: The output will be 10 and undefined. This is because the y variable is declared within the scope of the function and therefore cannot be globally accessed.
Copy link

Choose a reason for hiding this comment

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

Did you try running the code to see what it produces?

The second statement does not explain why the first output is 10.

Copy link
Author

Choose a reason for hiding this comment

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

You are right, the output is indeed 10 and undefined. I try making some research and it turns out that it is because the function has no return value although y has been declared and assigned a value.

Copy link

Choose a reason for hiding this comment

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

When I ran the script, the script threw an exception (because y is not declared). Just curious, did you not get an exception?

Comment on lines +20 to +22
Ans: The variable at line 5 is a globally declared as such it will return 1, while the variable at line 8 is a scope variable since is declared with the scope of the function.
Therefore, when the function is called it will console the x variable declared in its scope.

Copy link

Choose a reason for hiding this comment

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

I am not sure what you meant. The x at line 5 is certainly not globally declared.
I wonder how ChatGPT would answer this question.

Copy link
Author

Choose a reason for hiding this comment

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

I misinterpreted how the scope works. I didn't take into account where the console logs where being called. The console inside the function will refer to the local variable x and vice-versa.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jan 16, 2025
Made changes based on the reviews
@gai93003 gai93003 added the Complete Participant to add when work is complete and review comments have been addressed label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants