diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..30de70fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.acceptSuggestionOnEnter": "on" +} \ No newline at end of file diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..e554b011 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,65 @@ - - - - - - - - - - + - -
-

Library

-

Add books to your virtual library

-
+ + + + Book Library + + + + + + - + +
+

Library

+

Add books to your virtual library

+
-
-
- - - - - - - - -
-
+ - - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+
+
+ + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
TitleAuthorNumber of PagesRead
+ + + - - + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..0f77880d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,4 @@ let myLibrary = []; - window.addEventListener("load", function (e) { populateStorage(); render(); @@ -7,38 +6,42 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const titleEl = document.getElementById("title"); +const authorEl = document.getElementById("author"); +const pagesEl = document.getElementById("pages"); +const checkEl = document.getElementById("check"); +const submitBtnEl = document.getElementById("submit-btn"); + +submitBtnEl.addEventListener("click", function (event) { + event.preventDefault(); + submit(); +}); //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 == "" + !titleEl.value || + !authorEl.value || + !pagesEl.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(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); + myLibrary.push(book); render(); } } @@ -54,9 +57,9 @@ 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++) { @@ -77,9 +80,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -89,15 +92,17 @@ 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(); }); } } + +