-
-
Notifications
You must be signed in to change notification settings - Fork 69
ITPJ25LDN | Eyuel Abraham | Data-flows book library | week 2 #162
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
7ba3ba7
95fea27
2fede00
3da2929
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 |
---|---|---|
|
@@ -31,14 +31,16 @@ function submit() { | |
if ( | ||
title.value == null || | ||
title.value == "" || | ||
pages.value == null || | ||
author.value === "" || | ||
parseInt(pages.value) <=0 || | ||
isNaN(pages.value) || | ||
pages.value == "" | ||
) { | ||
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(); | ||
} | ||
} | ||
|
@@ -54,7 +56,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--) { | ||
table.deleteRow(n); | ||
} | ||
//insert updated row and cells | ||
|
@@ -77,9 +79,10 @@ function render() { | |
wasReadCell.appendChild(changeBut); | ||
let readStatus = ""; | ||
if (myLibrary[i].check == false) { | ||
readStatus = "Yes"; | ||
readStatus = "NO"; | ||
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 you don't read a book, color of button shouldn't be green, maybe we should change to something else in order to increase user experience. 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. I have added a RED background colour when readStatus = "NO"; |
||
changeBut.style.backgroundColor = "red" | ||
} else { | ||
readStatus = "No"; | ||
readStatus = "Yes"; | ||
} | ||
changeBut.innerText = readStatus; | ||
|
||
|
@@ -89,12 +92,12 @@ function render() { | |
}); | ||
|
||
//add delete button to every row and render again | ||
let delButton = document.createElement("button"); | ||
let delBut = document.createElement("button"); | ||
delBut.id = i + 5; | ||
deleteCell.appendChild(delBut); | ||
delBut.className = "btn btn-warning"; | ||
delBut.innerHTML = "Delete"; | ||
delBut.addEventListener("clicks", function () { | ||
delBut.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.
I'm still able to add a book even if one field is empty
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 have fixed the issue, thank you for the review.