Skip to content

Commit cb859a1

Browse files
committed
fixed some syntax mistakes
1 parent d3c51c0 commit cb859a1

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

debugging/book-library/script.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ window.addEventListener("load", function (e) {
77

88
function populateStorage() {
99
if (myLibrary.length == 0) {
10-
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
11-
let book2 = new Book(
12-
"The Old Man and the Sea",
13-
"Ernest Hemingway",
14-
"127",
15-
true
16-
);
10+
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true);
11+
let book2 = new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true);
1712
myLibrary.push(book1);
1813
myLibrary.push(book2);
1914
render();
@@ -31,36 +26,40 @@ function submit() {
3126
if (
3227
title.value == null ||
3328
title.value == "" ||
29+
author.value == null ||
30+
author.value == "" ||
3431
pages.value == null ||
3532
pages.value == ""
3633
) {
3734
alert("Please fill all fields!");
3835
return false;
3936
} else {
40-
let book = new Book(title.value, title.value, pages.value, check.checked);
41-
library.push(book);
37+
let book = new Book(title.value, author.value, pages.value, check.checked);
38+
myLibrary.push(book);
4239
render();
4340
}
4441
}
4542

46-
function Book(title, author, pages, check) {
47-
this.title = title;
48-
this.author = author;
49-
this.pages = pages;
50-
this.check = check;
43+
class Book {
44+
constructor(title, author, pages, check) {
45+
this.title = title;
46+
this.author = author;
47+
this.pages = pages;
48+
this.check = check;
49+
}
5150
}
5251

5352
function render() {
5453
let table = document.getElementById("display");
5554
let rowsNumber = table.rows.length;
5655
//delete old table
57-
for (let n = rowsNumber - 1; n > 0; n-- {
56+
for (let n = rowsNumber - 1; n > 0; n--) {
5857
table.deleteRow(n);
5958
}
6059
//insert updated row and cells
6160
let length = myLibrary.length;
6261
for (let i = 0; i < length; i++) {
63-
let row = table.insertRow(1);
62+
let row = table.insertRow(-1);
6463
let titleCell = row.insertCell(0);
6564
let authorCell = row.insertCell(1);
6665
let pagesCell = row.insertCell(2);
@@ -76,7 +75,7 @@ function render() {
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";
@@ -89,12 +88,12 @@ function render() {
8988
});
9089

9190
//add delete button to every row and render again
92-
let delButton = document.createElement("button");
91+
let delBut = document.createElement("button");
9392
delBut.id = i + 5;
9493
deleteCell.appendChild(delBut);
9594
delBut.className = "btn btn-warning";
9695
delBut.innerHTML = "Delete";
97-
delBut.addEventListener("clicks", function () {
96+
delBut.addEventListener("click", function () {
9897
alert(`You've deleted title: ${myLibrary[i].title}`);
9998
myLibrary.splice(i, 1);
10099
render();

0 commit comments

Comments
 (0)