Skip to content

Commit 0082b5a

Browse files
authored
Merge pull request #1 from nazaninsaedi/feature-BookLibrary
NW6 | NazaninSaedi | BookLibrary-JS3 | Week-1
2 parents ee31c86 + 6133172 commit 0082b5a

File tree

4 files changed

+53
-43
lines changed

4 files changed

+53
-43
lines changed

.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+
}

book-library/index.html

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title> </title>
4+
<title>My Book Library</title> <!-- Added a title for your webpage -->
55
<meta
66
charset="utf-8"
77
name="viewport"
88
content="width=device-width, initial-scale=1.0"
99
/>
10+
<!-- Updated script sources to use HTTPS -->
1011
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
1112
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
1213
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
14+
<!-- Updated CSS source to use HTTPS -->
1315
<link
1416
rel="stylesheet"
1517
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
1618
/>
19+
<!-- Included your custom CSS file -->
1720
<link rel="stylesheet" type="text/css" href="style.css" />
1821
</head>
1922

@@ -31,15 +34,15 @@ <h1>Library</h1>
3134
<div class="form-group">
3235
<label for="title">Title:</label>
3336
<input
34-
type="title"
37+
type="text" <!-- Corrected input type to "text" -->
3538
class="form-control"
3639
id="title"
3740
name="title"
3841
required
3942
/>
4043
<label for="author">Author: </label>
4144
<input
42-
type="author"
45+
type="text" <!-- Corrected input type to "text" -->
4346
class="form-control"
4447
id="author"
4548
name="author"
@@ -61,12 +64,13 @@ <h1>Library</h1>
6164
value=""
6265
/>Read
6366
</label>
64-
<input
65-
type="submit"
66-
value="Submit"
67+
<button
68+
type="button" <!-- Changed input type to button -->
6769
class="btn btn-primary"
6870
onclick="submit();"
69-
/>
71+
>
72+
Submit
73+
</button>
7074
</div>
7175
</div>
7276

@@ -81,13 +85,7 @@ <h1>Library</h1>
8185
</tr>
8286
</thead>
8387
<tbody>
84-
<tr>
85-
<td></td>
86-
<td></td>
87-
<td></td>
88-
<td></td>
89-
<td></td>
90-
</tr>
88+
<!-- Removed the default table row -->
9189
</tbody>
9290
</table>
9391

book-library/script.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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);
10+
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); // Corrected book title
1111
let book2 = new Book(
1212
"The Old Man and the Sea",
1313
"Ernest Hemingway",
@@ -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 || // Check for author input
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); // Passed author.value instead of title.value
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+
// Delete old table rows
57+
for (let n = rowsNumber - 1; n > 0; n--) { // Corrected the loop condition
5858
table.deleteRow(n);
5959
}
60-
//insert updated row and cells
60+
// Insert updated rows and cells
6161
let length = myLibrary.length;
6262
for (let i = 0; i < length; i++) {
6363
let row = table.insertRow(1);
@@ -70,31 +70,26 @@ function render() {
7070
cell2.innerHTML = myLibrary[i].author;
7171
cell3.innerHTML = myLibrary[i].pages;
7272

73-
//add and wait for action for read/unread button
73+
// Add read/unread button
7474
let changeBut = document.createElement("button");
7575
changeBut.id = i;
7676
changeBut.className = "btn btn-success";
7777
cell4.appendChild(changeBut);
78-
let readStatus = "";
79-
if (myLibrary[i].check == false) {
80-
readStatus = "Yes";
81-
} else {
82-
readStatus = "No";
83-
}
78+
let readStatus = myLibrary[i].check ? "No" : "Yes"; // Corrected readStatus assignment
8479
changeBut.innerHTML = readStatus;
8580

8681
changeBut.addEventListener("click", function () {
8782
myLibrary[i].check = !myLibrary[i].check;
8883
render();
8984
});
9085

91-
//add delete button to every row and render again
86+
// Add delete button
9287
let delButton = document.createElement("button");
93-
delBut.id = i + 5;
94-
cell5.appendChild(delBut);
95-
delBut.className = "btn btn-warning";
96-
delBut.innerHTML = "Delete";
97-
delBut.addEventListener("clicks", function () {
88+
delButton.id = i + 5; // Corrected variable name from delBut to delButton
89+
cell5.appendChild(delButton);
90+
delButton.className = "btn btn-warning";
91+
delButton.innerHTML = "Delete";
92+
delButton.addEventListener("click", function () { // Corrected event name from "clicks" to "click"
9893
alert(`You've deleted title: ${myLibrary[i].title}`);
9994
myLibrary.splice(i, 1);
10095
render();

book-library/style.css

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
/* Adjusted styles for the form group */
12
.form-group {
2-
width: 400px;
3-
height: 300px;
4-
align-self: left;
5-
padding-left: 20px;
3+
max-width: 400px;
4+
/* Changed width to max-width for responsiveness */
5+
margin: 0 auto;
6+
/* Center the form group */
7+
padding: 20px;
68
}
79

10+
/* Adjusted styles for buttons */
811
.btn {
9-
display: block;
12+
display: inline-block;
13+
/* Changed display to inline-block for buttons to appear inline */
14+
margin-right: 10px;
15+
/* Added margin-right for spacing between buttons */
1016
}
1117

18+
/* Adjusted styles for form-check-label */
1219
.form-check-label {
20+
display: inline-block;
21+
/* Changed display to inline-block for checkbox label */
1322
padding-left: 20px;
14-
margin: 5px 0px 5px 0px;
23+
margin: 5px 20px 5px 0;
24+
/* Adjusted margin for spacing */
1525
}
1626

27+
/* Adjusted styles for the add new book button */
1728
button.btn-info {
18-
margin: 20px;
19-
}
29+
margin: 20px auto;
30+
/* Center the button */
31+
display: block;
32+
/* Added display: block for full-width button */
33+
}

0 commit comments

Comments
 (0)