-
-
Notifications
You must be signed in to change notification settings - Fork 82
ITP London - Jan 2025 | Samunta Sunuwar| Module Data Flows | Book Library #203
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
93dff77
1470a9f
c1fd26d
19208f1
18ade97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your feedback, I have made changes as requested. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,19 @@ function submit() { | |
if ( | ||
title.value == null || | ||
title.value == "" || | ||
//adding author validation | ||
author.value == null || | ||
author.value == "" || | ||
pages.value == null || | ||
pages.value == "" | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your feedback, I have made changes as requested. |
||
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
let book = new Book(title.value, title.value, pages.value, check.checked); | ||
library.push(book); | ||
//creating new book using the correct author and read status | ||
let book = new Book(title.value, author.value, pages.value, check.checked); | ||
//fixing typo(corrected variable name casing) | ||
myLibrary.push(book); | ||
render(); | ||
} | ||
} | ||
|
@@ -54,13 +59,15 @@ function render() { | |
let table = document.getElementById("display"); | ||
let rowsNumber = table.rows.length; | ||
//delete old table | ||
for (let n = rowsNumber - 1; n > 0; n-- { | ||
//adding missing closing parenthesis | ||
for (let n = rowsNumber - 1; n > 0; n--) { | ||
table.deleteRow(n); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of deleting the table rows one by one, can you think of a more efficient way to remove all rows (except the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your feedback, I have made changes as requested. |
||
//insert updated row and cells | ||
let length = myLibrary.length; | ||
for (let i = 0; i < length; i++) { | ||
let row = table.insertRow(1); | ||
//appending the row to the end of the table | ||
let row = table.insertRow(-1); | ||
let titleCell = row.insertCell(0); | ||
let authorCell = row.insertCell(1); | ||
let pagesCell = row.insertCell(2); | ||
|
@@ -74,30 +81,35 @@ function render() { | |
let changeBut = document.createElement("button"); | ||
changeBut.id = i; | ||
changeBut.className = "btn btn-success"; | ||
wasReadCell.appendChild(changeBut); | ||
|
||
|
||
//setting the button text based on read status (fixing logic by assigning correct boolean value) | ||
let readStatus = ""; | ||
if (myLibrary[i].check == false) { | ||
if (myLibrary[i].check == true) { | ||
readStatus = "Yes"; | ||
} else { | ||
readStatus = "No"; | ||
} | ||
changeBut.innerText = readStatus; | ||
wasReadCell.appendChild(changeBut); | ||
|
||
changeBut.addEventListener("click", function () { | ||
myLibrary[i].check = !myLibrary[i].check; | ||
render(); | ||
}); | ||
|
||
//add delete button to every row and render again | ||
let delButton = document.createElement("button"); | ||
delBut.id = i + 5; | ||
deleteCell.appendChild(delBut); | ||
delBut.className = "btn btn-warning"; | ||
delBut.innerHTML = "Delete"; | ||
delBut.addEventListener("clicks", function () { | ||
alert(`You've deleted title: ${myLibrary[i].title}`); | ||
myLibrary.splice(i, 1); | ||
render(); | ||
}); | ||
// fixed: using one consistent button variable | ||
let delButton = document.createElement("button"); | ||
delButton.id = `delete-${i}`; // optional: clearer ID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job in recognizing the need to ensure unique id value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you |
||
delButton.className = "btn btn-warning"; | ||
delButton.innerHTML = "Delete"; | ||
deleteCell.appendChild(delButton); | ||
|
||
// using correct button variable name | ||
delButton.addEventListener("click", function () { | ||
alert(`You've deleted title: ${myLibrary[i].title}`); | ||
myLibrary.splice(i, 1); | ||
render(); | ||
}); | ||
} | ||
} |
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.
Good job in fixing most of the errors in the HTML code.
According to https://validator.w3.org/, there are still some errors in the HTML code. Can you fix these errors?
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.
Thank you for your feedback, I have made changes as requested.