@@ -25,20 +25,20 @@ const author = document.getElementById("author");
2525const pages = document . getElementById ( "pages" ) ;
2626const check = document . getElementById ( "check" ) ;
2727
28- //check the right input from forms and if its ok -> add the new book (object in array)
29- //via Book function and start render function
3028function submit ( ) {
3129 if (
3230 title . value == null ||
3331 title . value == "" ||
32+ author . value == null ||
33+ author . value == "" ||
3434 pages . value == null ||
3535 pages . value == ""
3636 ) {
3737 alert ( "Please fill all fields!" ) ;
3838 return false ;
3939 } else {
40- let book = new Book ( title . value , title . value , pages . value , check . checked ) ;
41- library . push ( book ) ;
40+ let book = new Book ( title . value , author . value , pages . value , check . checked ) ;
41+ myLibrary . push ( book ) ;
4242 render ( ) ;
4343 }
4444}
@@ -53,11 +53,11 @@ function Book(title, author, pages, check) {
5353function render ( ) {
5454 let table = document . getElementById ( "display" ) ;
5555 let rowsNumber = table . rows . length ;
56- //delete old table
57- for ( let n = rowsNumber - 1 ; n > 0 ; n -- {
56+
57+ for ( let n = rowsNumber - 1 ; n > 0 ; n -- ) {
5858 table . deleteRow ( n ) ;
5959 }
60- //insert updated row and cells
60+
6161 let length = myLibrary . length ;
6262 for ( let i = 0 ; i < length ; i ++ ) {
6363 let row = table . insertRow ( 1 ) ;
@@ -70,13 +70,12 @@ function render() {
7070 authorCell . innerHTML = myLibrary [ i ] . author ;
7171 pagesCell . innerHTML = myLibrary [ i ] . pages ;
7272
73- //add and wait for action for read/unread button
7473 let changeBut = document . createElement ( "button" ) ;
7574 changeBut . id = i ;
7675 changeBut . className = "btn btn-success" ;
7776 wasReadCell . appendChild ( changeBut ) ;
7877 let readStatus = "" ;
79- if ( myLibrary [ i ] . check == false ) {
78+ if ( myLibrary [ i ] . check == true ) {
8079 readStatus = "Yes" ;
8180 } else {
8281 readStatus = "No" ;
@@ -88,13 +87,13 @@ function render() {
8887 render ( ) ;
8988 } ) ;
9089
91- //add delete button to every row and render again
92- let delButton = document . createElement ( "button" ) ;
90+ let delBut = document . createElement ( "button" ) ;
9391 delBut . id = i + 5 ;
9492 deleteCell . appendChild ( delBut ) ;
9593 delBut . className = "btn btn-warning" ;
9694 delBut . innerHTML = "Delete" ;
97- delBut . addEventListener ( "clicks" , function ( ) {
95+
96+ delBut . addEventListener ( "click" , function ( ) {
9897 alert ( `You've deleted title: ${ myLibrary [ i ] . title } ` ) ;
9998 myLibrary . splice ( i , 1 ) ;
10099 render ( ) ;
0 commit comments