Skip to content

Commit bdfa3c2

Browse files
committed
Completed Book Library
1 parent 935dc0b commit bdfa3c2

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

debugging/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

debugging/book-library/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<title> </title>
@@ -65,7 +65,7 @@ <h1>Library</h1>
6565
type="submit"
6666
value="Submit"
6767
class="btn btn-primary"
68-
onclick="submit();"
68+
onclick="submit()"
6969
/>
7070
</div>
7171
</div>

debugging/book-library/script.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ const author = document.getElementById("author");
2525
const pages = document.getElementById("pages");
2626
const 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
3028
function submit() {
3129
if (
3230
title.value == null ||
3331
title.value == "" ||
32+
author.value == null ||
33+
author.value == "" ||
3434
pages.value == null ||
3535
pages.value == ""
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
}
@@ -53,11 +53,11 @@ function Book(title, author, pages, check) {
5353
function render() {
5454
let table = document.getElementById("display");
5555
let rowsNumber = table.rows.length;
56-
//delete old table
57-
for (let n = rowsNumber - 1; n > 0; n-- {
56+
57+
for (let n = rowsNumber - 1; n > 0; n--) {
5858
table.deleteRow(n);
5959
}
60-
//insert updated row and cells
60+
6161
let length = myLibrary.length;
6262
for (let i = 0; i < length; i++) {
6363
let row = table.insertRow(1);
@@ -70,13 +70,12 @@ function render() {
7070
authorCell.innerHTML = myLibrary[i].author;
7171
pagesCell.innerHTML = myLibrary[i].pages;
7272

73-
//add and wait for action for read/unread button
7473
let changeBut = document.createElement("button");
7574
changeBut.id = i;
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";
@@ -88,13 +87,13 @@ function render() {
8887
render();
8988
});
9089

91-
//add delete button to every row and render again
92-
let delButton = document.createElement("button");
90+
let delBut = document.createElement("button");
9391
delBut.id = i + 5;
9492
deleteCell.appendChild(delBut);
9593
delBut.className = "btn btn-warning";
9694
delBut.innerHTML = "Delete";
97-
delBut.addEventListener("clicks", function () {
95+
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)