@@ -25,20 +25,26 @@ 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 ( ) {
29+ // correct author validation
3130 if (
3231 title . value == null ||
3332 title . value == "" ||
33+ author . value == null ||
34+ author . value == "" ||
3435 pages . value == null ||
3536 pages . value == ""
3637 ) {
3738 alert ( "Please fill all fields!" ) ;
3839 return false ;
3940 } else {
40- let book = new Book ( title . value , title . value , pages . value , check . checked ) ;
41- library . push ( book ) ;
41+ //correct changed second title.value to author.value
42+ let book = new Book ( title . value , author . value , pages . value , check . checked ) ;
43+
44+
45+ //correct name is myLibrary
46+ myLibrary . push ( book ) ;
47+
4248 render ( ) ;
4349 }
4450}
@@ -53,11 +59,12 @@ function Book(title, author, pages, check) {
5359function render ( ) {
5460 let table = document . getElementById ( "display" ) ;
5561 let rowsNumber = table . rows . length ;
56- //delete old table
57- for ( let n = rowsNumber - 1 ; n > 0 ; n -- {
62+
63+ //correct closing parenthesis
64+ for ( let n = rowsNumber - 1 ; n > 0 ; n -- ) {
5865 table . deleteRow ( n ) ;
5966 }
60- //insert updated row and cells
67+
6168 let length = myLibrary . length ;
6269 for ( let i = 0 ; i < length ; i ++ ) {
6370 let row = table . insertRow ( 1 ) ;
@@ -70,16 +77,26 @@ function render() {
7077 authorCell . innerHTML = myLibrary [ i ] . author ;
7178 pagesCell . innerHTML = myLibrary [ i ] . pages ;
7279
73- //add and wait for action for read/unread button
80+ //READ BUTTON
7481 let changeBut = document . createElement ( "button" ) ;
7582 changeBut . id = i ;
76- changeBut . className = "btn btn-success" ;
83+
84+
85+ //correct color
86+
7787 wasReadCell . appendChild ( changeBut ) ;
7888 let readStatus = "" ;
79- if ( myLibrary [ i ] . check == false ) {
89+
90+
91+ //correct If checked is true readStatus Yes
92+ if ( myLibrary [ i ] . check == true ) {
8093 readStatus = "Yes" ;
94+ //green class
95+ changeBut . className = "btn btn-success" ;
8196 } else {
8297 readStatus = "No" ;
98+ //correctred
99+ changeBut . className = "btn btn-danger" ;
83100 }
84101 changeBut . innerText = readStatus ;
85102
@@ -88,16 +105,24 @@ function render() {
88105 render ( ) ;
89106 } ) ;
90107
91- //add delete button to every row and render again
108+ //delete btn
92109 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 ( ) {
110+
111+
112+ //correct delButton
113+ delButton . id = i + 5 ;
114+
115+ //correct
116+ deleteCell . appendChild ( delButton ) ;
117+ //correct
118+ delButton . className = "btn btn-warning" ;
119+ //correct
120+ delButton . innerHTML = "Delete" ;
121+ //correct delButtonand click
122+ delButton . addEventListener ( "click" , function ( ) {
98123 alert ( `You've deleted title: ${ myLibrary [ i ] . title } ` ) ;
99124 myLibrary . splice ( i , 1 ) ;
100125 render ( ) ;
101126 } ) ;
102127 }
103- }
128+ }
0 commit comments