diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c4d4e3a1..00000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -**/node_modules -.DS_Store -**/.DS_Store \ No newline at end of file diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..56cd30c2 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,20 +1,16 @@ - - + + - - + Book Library + + - + href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> + @@ -31,20 +27,20 @@

Library

+ > + > Library id="pages" name="pages" required - /> + > + onclick="submit()" + >
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..7a37adb0 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,10 @@ let myLibrary = []; +function setup() { + populateStorage(); + render(); +} + window.addEventListener("load", function (e) { populateStorage(); render(); @@ -14,9 +19,9 @@ function populateStorage() { "127", true ); + myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -28,17 +33,12 @@ 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 || - title.value == "" || - pages.value == null || - pages.value == "" - ) { + if (title.value == "" || author.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,32 +54,36 @@ 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 let length = myLibrary.length; + for (let i = 0; i < length; i++) { let row = table.insertRow(1); + let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2); let wasReadCell = row.insertCell(3); let deleteCell = row.insertCell(4); + titleCell.innerHTML = myLibrary[i].title; 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; @@ -90,11 +94,13 @@ function 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 () { + + 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(); diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..ee1d910b 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -2,7 +2,7 @@ width: 400px; height: 300px; align-self: left; - padding-left: 20px; + text-align: 20px; } .btn {