-
-
Notifications
You must be signed in to change notification settings - Fork 72
ITP-Jan| NW | Jovy So | Module-Data-Flows | Book-library #222
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,15 @@ function populateStorage() { | |
); | ||
myLibrary.push(book1); | ||
myLibrary.push(book2); | ||
render(); | ||
} | ||
render(); | ||
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. If we call |
||
} | ||
|
||
const title = document.getElementById("title"); | ||
const author = document.getElementById("author"); | ||
const pages = document.getElementById("pages"); | ||
const check = document.getElementById("check"); | ||
|
||
//check the right input from forms and if its ok -> add the new book (object in array) | ||
//via Book function and start render function | ||
function submit() { | ||
if ( | ||
title.value == null || | ||
|
@@ -37,8 +35,8 @@ function submit() { | |
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
let book = new Book(title.value, title.value, pages.value, check.checked); | ||
library.push(book); | ||
let book = new Book(title.value, author.value, pages.value, check.checked); | ||
myLibrary.push(book); | ||
render(); | ||
} | ||
} | ||
|
@@ -53,11 +51,9 @@ function Book(title, author, pages, check) { | |
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--) { | ||
table.deleteRow(n); | ||
} | ||
Comment on lines
-57
to
56
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 |
||
//insert updated row and cells | ||
let length = myLibrary.length; | ||
for (let i = 0; i < length; i++) { | ||
let row = table.insertRow(1); | ||
|
@@ -70,16 +66,15 @@ function render() { | |
authorCell.innerHTML = myLibrary[i].author; | ||
pagesCell.innerHTML = myLibrary[i].pages; | ||
|
||
//add and wait for action for read/unread button | ||
let changeBut = document.createElement("button"); | ||
changeBut.id = i; | ||
changeBut.className = "btn btn-success"; | ||
wasReadCell.appendChild(changeBut); | ||
let readStatus = ""; | ||
if (myLibrary[i].check == false) { | ||
readStatus = "Yes"; | ||
} else { | ||
readStatus = "No"; | ||
} else { | ||
readStatus = "Yes"; | ||
} | ||
changeBut.innerText = readStatus; | ||
|
||
|
@@ -88,13 +83,12 @@ function render() { | |
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 () { | ||
let delButton = document.createElement("button"); | ||
delButton.id = i + 5; | ||
deleteCell.appendChild(delButton); | ||
delButton.className = "btn btn-warning"; | ||
delButton.innerHTML = "Delete"; | ||
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.
In terms of input validation (lines 30-36),
.value
benull
? (Do we need to checksomeInputElement.value == null
?)" "
.Lines 70, 87:
id
attributes unique?Line 65:
<i>
.Can you suggest a more consistent naming convention for the variables representing the two buttons, currently named
changeBut
anddelButton
?Line 74-79: Can you use the conditional operator,
? :
to simplify these statements into one line of code?