You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
myLibrary.push(book);// ???? the var called MyLibrary bro
44
-
render();// tell now where as submit event maybe later I will check
39
+
myLibrary.push(book);
40
+
render();
45
41
}
46
42
}
47
-
letbook1=newBook("Robison Crusoe","Daniel Defoe","252",true);///why i have this in populteStorage and here
48
43
49
-
//function to create a new book as an object
50
-
functionBook(title,author,pages,check){
44
+
functionBook(title,author,pages,check){
51
45
this.title=title;
52
46
this.author=author;
53
47
this.pages=pages;
@@ -58,16 +52,16 @@ function render() {
58
52
lettable=document.getElementById("display");
59
53
letrowsNumber=table.rows.length;
60
54
//delete old table
61
-
for(letn=rowsNumber-1;n>0;n--){//n>0 because we will delete all rows except the first one header
62
-
table.deleteRow(n);//.deleteRow is a built-in JS function it remove the row by index
55
+
for(letn=rowsNumber-1;n>0;n--){
56
+
table.deleteRow(n);
63
57
}
64
58
//insert updated row and cells
65
59
letlength=myLibrary.length;
66
60
for(leti=0;i<length;i++){
67
61
letrow=table.insertRow(1);// why (1) not i+1 insert <tr> with four <td>
68
62
lettitleCell=row.insertCell(0);// the table.rows and row.cells are HTMLCollection,not a real array, but they behave like array(indexed,length) . they are DOM collections
69
63
letauthorCell=row.insertCell(1);
70
-
letpagesCell=row.insertCell(2);
64
+
letpagesCell=row.insertCell(2);
71
65
letwasReadCell=row.insertCell(3);
72
66
letdeleteCell=row.insertCell(4);// it is like insert for <td> </td>
73
67
titleCell.innerHTML=myLibrary[i].title;//filling the cells why innerHTML
@@ -78,32 +72,32 @@ function render() {
78
72
letchangeBut=document.createElement("button");
79
73
changeBut.id=i;// give the button the index of the book object
80
74
changeBut.className="btn btn-success";
81
-
wasReadCell.appendChild(changeBut);
75
+
wasReadCell.appendChild(changeBut);
82
76
letreadStatus="";
83
-
if(myLibrary[i].check==true){// why not ===
77
+
if(myLibrary[i].check===true){
84
78
readStatus="Yes";
85
79
}else{
86
80
readStatus="No";
87
81
}
88
-
changeBut.innerText=readStatus;// fill the button with yes or no
82
+
changeBut.innerText=readStatus;
89
83
90
84
changeBut.addEventListener("click",function(){
91
-
myLibrary[i].check=!myLibrary[i].check;//when we click will change yes to no and no to yes
85
+
myLibrary[i].check=!myLibrary[i].check;
92
86
render();
93
87
});
94
88
95
89
//add delete button to every row and render again
96
-
//delButton
90
+
97
91
letdelButton=document.createElement("button");
98
-
delButton.id=i+5;// I think there is an issue here if we have more than five books
0 commit comments