11let myLibrary = [ ] ;
22
3- window . addEventListener ( "load" , function ( e ) {
3+ window . addEventListener ( "load" , function ( ) {
44 populateStorage ( ) ;
55 render ( ) ;
66} ) ;
@@ -14,9 +14,8 @@ function populateStorage() {
1414 "127" ,
1515 true
1616 ) ;
17- myLibrary . push ( book1 ) ;
17+ myLibrary . push ( book1 ) ;
1818 myLibrary . push ( book2 ) ;
19- render ( ) ;
2019 }
2120}
2221
@@ -31,10 +30,14 @@ function submit() {
3130 if (
3231 title . value == null ||
3332 title . value == "" ||
33+ author . value == null ||
34+ author . value == "" ||
3435 pages . value == null ||
35- pages . value == ""
36+ pages . value == "" ||
37+ pages . value <= 0 ||
38+ pages . value != parseInt ( )
3639 ) {
37- alert ( "Please fill all fields !" ) ;
40+ alert ( "Please fill with valid input !" ) ;
3841 return false ;
3942 } else {
4043 let book = new Book ( title . value , author . value , pages . value , check . checked ) ;
@@ -71,19 +74,19 @@ function render() {
7174 pagesCell . innerHTML = myLibrary [ i ] . pages ;
7275
7376 //add and wait for action for read/unread button
74- let changeBut = document . createElement ( "button" ) ;
75- changeBut . id = i ;
76- changeBut . className = "btn btn-success" ;
77- wasReadCell . appendChild ( changeBut ) ;
77+ let changeButton = document . createElement ( "button" ) ;
78+ changeButton . id = i ;
79+ changeButton . className = "btn btn-success" ;
80+ wasReadCell . appendChild ( changeButton ) ;
7881 let readStatus = "" ;
7982 if ( myLibrary [ i ] . check == false ) {
8083 readStatus = "No" ;
8184 } else {
8285 readStatus = "Yes" ;
8386 }
84- changeBut . innerText = readStatus ;
87+ changeButton . innerText = readStatus ;
8588
86- changeBut . addEventListener ( "click" , function ( ) {
89+ changeButton . addEventListener ( "click" , function ( ) {
8790 myLibrary [ i ] . check = ! myLibrary [ i ] . check ;
8891 render ( ) ;
8992 } ) ;
@@ -110,12 +113,11 @@ function render() {
110113 // });
111114
112115 //add delete button to every row and render again
113- const delButton = document . createElement ( "button" ) ;
114- delButton . id = i + 5 ;
115- deleteCell . appendChild ( delButton ) ;
116- delButton . className = "btn btn-warning" ;
117- delButton . innerHTML = "Delete" ;
118- delButton . addEventListener ( "click" , function ( ) {
116+ const deleteButton = document . createElement ( "button" ) ;
117+ deleteCell . appendChild ( deleteButton ) ;
118+ deleteButton . className = "btn btn-warning" ;
119+ deleteButton . innerHTML = "Delete" ;
120+ deleteButton . addEventListener ( "click" , function ( ) {
119121 alert ( `You've deleted title: ${ myLibrary [ i ] . title } ` ) ;
120122 myLibrary . splice ( i , 1 ) ;
121123 render ( ) ;
0 commit comments