11let myLibrary = [ ] ;
22
3- window . addEventListener ( "load" , function ( e ) {
3+ window . addEventListener ( "load" , function ( ) {
44 populateStorage ( ) ;
55 render ( ) ;
66} ) ;
@@ -29,32 +29,34 @@ const check = document.getElementById("check");
2929//via Book function and start render function
3030function submit ( ) {
3131 if (
32- title . value == null ||
33- title . value == "" ||
34- pages . value == null ||
35- pages . value == ""
32+ title . value === "" ||
33+ author . value = == "" ||
34+ pages . value === "" ||
35+ ! check . checked
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}
4545
46- function Book ( title , author , pages , check ) {
47- this . title = title ;
48- this . author = author ;
49- this . pages = pages ;
50- this . check = check ;
46+ class Book {
47+ constructor ( title , author , pages , check ) {
48+ this . title = title ;
49+ this . author = author ;
50+ this . pages = pages ;
51+ this . check = check ;
52+ }
5153}
5254
5355function 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
@@ -76,7 +78,7 @@ function render() {
7678 changeBut . className = "btn btn-success" ;
7779 wasReadCell . appendChild ( changeBut ) ;
7880 let readStatus = "" ;
79- if ( myLibrary [ i ] . check == false ) {
81+ if ( myLibrary [ i ] . check ) {
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