Skip to content

Commit e6be8dc

Browse files
committed
HTML codes and Js codes debugged
1 parent 3a422e9 commit e6be8dc

3 files changed

Lines changed: 109 additions & 69 deletions

File tree

‎debugging/book-library/index.html‎

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,68 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
4-
<title> </title>
5-
<meta
6-
charset="utf-8"
7-
name="viewport"
8-
content="width=device-width, initial-scale=1.0"
9-
/>
10-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
11-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
12-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
4+
<title>Book Library</title>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
137
<link
148
rel="stylesheet"
159
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
1610
/>
17-
<link rel="stylesheet" type="text/css" href="style.css" />
11+
<link rel="stylesheet" href="style.css" />
1812
</head>
1913

2014
<body>
21-
<div class="jumbotron text-center">
15+
<div class="header">
2216
<h1>Library</h1>
2317
<p>Add books to your virtual library</p>
18+
<button
19+
id="add-btn"
20+
data-toggle="collapse"
21+
data-target="#demo"
22+
class="btn"
23+
>
24+
Add new book
25+
</button>
2426
</div>
2527

26-
<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
27-
Add new book
28-
</button>
29-
3028
<div id="demo" class="collapse">
31-
<div class="form-group">
32-
<label for="title">Title:</label>
33-
<input
34-
type="title"
35-
class="form-control"
36-
id="title"
37-
name="title"
38-
required
39-
/>
40-
<label for="author">Author: </label>
41-
<input
42-
type="author"
43-
class="form-control"
44-
id="author"
45-
name="author"
46-
required
47-
/>
48-
<label for="pages">Pages:</label>
49-
<input
50-
type="number"
51-
class="form-control"
52-
id="pages"
53-
name="pages"
54-
required
55-
/>
56-
<label class="form-check-label">
29+
<form id="book-form">
30+
<div class="form-group">
31+
<label for="title">Title:</label>
5732
<input
58-
type="checkbox"
59-
class="form-check-input"
60-
id="check"
61-
value=""
62-
/>Read
63-
</label>
64-
<input
65-
type="submit"
66-
value="Submit"
67-
class="btn btn-primary"
68-
onclick="submit();"
69-
/>
70-
</div>
33+
type="text"
34+
class="form-control"
35+
id="title"
36+
name="title"
37+
required
38+
/>
39+
<label for="author">Author: </label>
40+
<input
41+
type="text"
42+
class="form-control"
43+
id="author"
44+
name="author"
45+
required
46+
/>
47+
<label for="pages">Pages:</label>
48+
<input
49+
type="number"
50+
class="form-control"
51+
id="pages"
52+
name="pages"
53+
required
54+
/>
55+
<label for="check" class="form-check-label">
56+
<input
57+
type="checkbox"
58+
class="form-check-input"
59+
id="check"
60+
value=""
61+
/>Read
62+
</label>
63+
<button id="submit-btn" class="btn" type="submit">submit</button>
64+
</div>
65+
</form>
7166
</div>
7267

7368
<table class="table" id="display">
@@ -92,5 +87,8 @@ <h1>Library</h1>
9287
</table>
9388

9489
<script src="script.js"></script>
90+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
91+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
92+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
9593
</body>
9694
</html>

‎debugging/book-library/script.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ function populateStorage() {
1616
);
1717
myLibrary.push(book1);
1818
myLibrary.push(book2);
19-
render();
2019
}
2120
}
2221

22+
const addBtn = document.getElementById("add-btn");
2323
const title = document.getElementById("title");
2424
const author = document.getElementById("author");
2525
const pages = document.getElementById("pages");
2626
const check = document.getElementById("check");
27+
const bookForm = document.getElementById("book-form");
2728

29+
//
30+
bookForm.addEventListener("submit", function (e) {
31+
e.preventDefault(); // stop page reload
32+
submit(); // call your function
33+
});
2834
//check the right input from forms and if its ok -> add the new book (object in array)
2935
//via Book function and start render function
3036
function submit() {
@@ -37,9 +43,11 @@ function submit() {
3743
alert("Please fill all fields!");
3844
return false;
3945
} else {
40-
let book = new Book(title.value, title.value, pages.value, check.checked);
41-
library.push(book);
46+
let book3 = new Book(title.value, author.value, pages.value, check.checked);
47+
myLibrary.push(book3);
4248
render();
49+
bookForm.reset();
50+
document.getElementById("demo").classList.remove("show");
4351
}
4452
}
4553

@@ -54,7 +62,7 @@ function render() {
5462
let table = document.getElementById("display");
5563
let rowsNumber = table.rows.length;
5664
//delete old table
57-
for (let n = rowsNumber - 1; n > 0; n-- {
65+
for (let n = rowsNumber - 1; n > 0; n--) {
5866
table.deleteRow(n);
5967
}
6068
//insert updated row and cells
@@ -76,7 +84,7 @@ function render() {
7684
changeBut.className = "btn btn-success";
7785
wasReadCell.appendChild(changeBut);
7886
let readStatus = "";
79-
if (myLibrary[i].check == false) {
87+
if (myLibrary[i].check === true) {
8088
readStatus = "Yes";
8189
} else {
8290
readStatus = "No";
@@ -89,12 +97,12 @@ function render() {
8997
});
9098

9199
//add delete button to every row and render again
92-
let delButton = document.createElement("button");
100+
let delBut = document.createElement("button");
93101
delBut.id = i + 5;
94102
deleteCell.appendChild(delBut);
95103
delBut.className = "btn btn-warning";
96104
delBut.innerHTML = "Delete";
97-
delBut.addEventListener("clicks", function () {
105+
delBut.addEventListener("click", function () {
98106
alert(`You've deleted title: ${myLibrary[i].title}`);
99107
myLibrary.splice(i, 1);
100108
render();

‎debugging/book-library/style.css‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1+
html {
2+
scroll-behavior: smooth;
3+
}
4+
5+
.header {
6+
background: #2f2e57;
7+
display: flex;
8+
flex-direction: column;
9+
justify-content: center;
10+
align-items: center;
11+
}
12+
.header h1 {
13+
color: white;
14+
font-size: 50px;
15+
padding: 20px;
16+
}
17+
.header p {
18+
color: white;
19+
font-size: 30px;
20+
padding: 20px;
21+
}
22+
123
.form-group {
24+
background-color: #2f2e57;
25+
color: whitesmoke;
226
width: 400px;
3-
height: 300px;
27+
height: 350px;
428
align-self: left;
5-
padding-left: 20px;
29+
padding: 20px;
30+
margin: 20px auto;
31+
border-radius: 10px;
32+
gap: 10px;
633
}
734

835
.btn {
9-
display: block;
36+
background-color: skyblue;
37+
display: flex;
38+
margin: 20px auto;
39+
padding: 10px;
40+
border-radius: 10px;
41+
font-size: 20px;
42+
border: none;
43+
outline: none;
44+
}
45+
.btn:focus {
46+
outline: none;
47+
box-shadow: none;
1048
}
1149

1250
.form-check-label {
1351
padding-left: 20px;
1452
margin: 5px 0px 5px 0px;
1553
}
16-
17-
button.btn-info {
18-
margin: 20px;
19-
}

0 commit comments

Comments
 (0)