@@ -16,7 +16,7 @@ function populateStorage() {
1616 ) ;
1717 myLibrary . push ( book1 ) ;
1818 myLibrary . push ( book2 ) ;
19- render ( ) ;
19+
2020 }
2121}
2222
@@ -27,18 +27,20 @@ const check = document.getElementById("check");
2727
2828//check the right input from forms and if its ok -> add the new book (object in array)
2929//via Book function and start render function
30- function submit ( ) {
30+ function addBook ( ) {
3131 if (
3232 title . value == null ||
3333 title . value == "" ||
3434 pages . value == null ||
35- pages . value == ""
35+ pages . value == "" ||
36+ author . value == null ||
37+ author . value == ""
3638 ) {
3739 alert ( "Please fill all fields!" ) ;
3840 return false ;
3941 } else {
40- let book = new Book ( title . value , title . value , pages . value , check . checked ) ;
41- library . push ( book ) ;
42+ let book = new Book ( title . value , author . value , pages . value , check . checked ) ;
43+ myLibrary . push ( book ) ;
4244 render ( ) ;
4345 }
4446}
@@ -54,7 +56,7 @@ function render() {
5456 let table = document . getElementById ( "display" ) ;
5557 let rowsNumber = table . rows . length ;
5658 //delete old table
57- for ( let n = rowsNumber - 1 ; n > 0 ; n -- {
59+ for ( let n = rowsNumber - 1 ; n > 0 ; n -- ) {
5860 table . deleteRow ( n ) ;
5961 }
6062 //insert updated row and cells
@@ -69,14 +71,14 @@ function render() {
6971 titleCell . innerHTML = myLibrary [ i ] . title ;
7072 authorCell . innerHTML = myLibrary [ i ] . author ;
7173 pagesCell . innerHTML = myLibrary [ i ] . pages ;
72-
74+
7375 //add and wait for action for read/unread button
7476 let changeBut = document . createElement ( "button" ) ;
7577 changeBut . id = i ;
7678 changeBut . className = "btn btn-success" ;
7779 wasReadCell . appendChild ( changeBut ) ;
7880 let readStatus = "" ;
79- if ( myLibrary [ i ] . check == false ) {
81+ if ( myLibrary [ i ] . check == true ) {
8082 readStatus = "Yes" ;
8183 } else {
8284 readStatus = "No" ;
@@ -90,11 +92,11 @@ function render() {
9092
9193 //add delete button to every row and render again
9294 let delButton = document . createElement ( "button" ) ;
93- delBut . id = i + 5 ;
94- deleteCell . appendChild ( delBut ) ;
95- delBut . className = "btn btn-warning" ;
96- delBut . innerHTML = "Delete" ;
97- delBut . addEventListener ( "clicks " , function ( ) {
95+ delButton . id = i ;
96+ deleteCell . appendChild ( delButton ) ;
97+ delButton . className = "btn btn-warning" ;
98+ delButton . innerHTML = "Delete" ;
99+ delButton . addEventListener ( "click " , function ( ) {
98100 alert ( `You've deleted title: ${ myLibrary [ i ] . title } ` ) ;
99101 myLibrary . splice ( i , 1 ) ;
100102 render ( ) ;
0 commit comments