Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6fe2b67
missing bracket closure on line 57
AngelaMcLeary Apr 9, 2026
b647506
fix syntax error on line 92 update variable
AngelaMcLeary Apr 9, 2026
dc2969c
add title to html file
AngelaMcLeary Apr 9, 2026
6146e7f
update variable name to myLibrary on Line 41
AngelaMcLeary Apr 9, 2026
731ac4c
return of author value on line 40 to allow correct output
AngelaMcLeary Apr 9, 2026
377bd24
fix typo change click to clicks on line 92
AngelaMcLeary Apr 9, 2026
200d98c
fix result of input status of book when read is selected to YES line …
AngelaMcLeary Apr 9, 2026
6d570e5
update validation requiremtns on lines 36-41
AngelaMcLeary Apr 9, 2026
ff6b347
fix formatting issues in submit and render functions
AngelaMcLeary Apr 9, 2026
376af2f
update input type for title and author
AngelaMcLeary Apr 10, 2026
1d6d91b
update improper meta tag
AngelaMcLeary Apr 11, 2026
366d541
update html tag to include language
AngelaMcLeary Apr 11, 2026
957ce0b
update remove empty rows
AngelaMcLeary Apr 11, 2026
b6bb86f
update scripts to include defer
AngelaMcLeary Apr 11, 2026
c87d77d
update add form element for user data input
AngelaMcLeary Apr 12, 2026
89af4d0
update to remove onclick submit from html
AngelaMcLeary Apr 12, 2026
1a97cd5
update to fix remove form and onclick
AngelaMcLeary Apr 12, 2026
6822947
update to remove invalid css in form-group
AngelaMcLeary Apr 12, 2026
5350f6e
update code to clear fields after submission
AngelaMcLeary Apr 12, 2026
9228c2f
update main container in html
AngelaMcLeary Apr 12, 2026
5062215
update css to meet accessibility requirements
AngelaMcLeary Apr 12, 2026
10ae61f
update spacing for form
AngelaMcLeary Apr 12, 2026
ece0823
update css for h1, h2 and update changeBut and deleteBut to ..Btn
AngelaMcLeary Apr 12, 2026
6b1fb53
update let to const for myLibrary variable
AngelaMcLeary Apr 12, 2026
380c723
update variable delbut to deleteBtn
AngelaMcLeary Apr 12, 2026
820a4e1
update converted page number from string to number
AngelaMcLeary Apr 13, 2026
f170475
update submit function to handle page as numbers and fix validation c…
AngelaMcLeary Apr 13, 2026
94388ba
update if staement and use tenary operator
AngelaMcLeary Apr 13, 2026
eb6981c
update unneccessay code changeBtn.id and deleteBtn.id
AngelaMcLeary Apr 13, 2026
adfb8c0
update remove index parameter from deleteBtn.addEventListener
AngelaMcLeary Apr 13, 2026
d53e21d
update change order of operation for delete alert
AngelaMcLeary Apr 13, 2026
e4c4826
update html to at toast div
AngelaMcLeary Apr 13, 2026
e29da34
update function for toast when item is deleted
AngelaMcLeary Apr 13, 2026
d89ea46
update alert message with function call
AngelaMcLeary Apr 13, 2026
6fff30c
update toast css and change show to visible
AngelaMcLeary Apr 13, 2026
eab8a1f
update toast style in css, remove inline style in jumbotron
AngelaMcLeary Apr 13, 2026
851e2ce
update style text in alert
AngelaMcLeary Apr 13, 2026
4e49d1d
update toast style
AngelaMcLeary Apr 13, 2026
c96752d
update formatting with prettier
AngelaMcLeary Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 48 additions & 75 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title> </title>
<meta
charset="utf-8"
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Book Library</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
Expand All @@ -18,79 +17,53 @@
</head>

<body>
<div class="jumbotron text-center">
<h1>Library</h1>
<p>Add books to your virtual library</p>
</div>
<main>
<div class="jumbotron">
<h1>Library</h1>
<h2>Add books to your virtual library</h2>
</div>
<div class="toast" id="toast"></div>
<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
Add new book
</button>

<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
Add new book
</button>
<div id="demo" class="collapse">
<div class="form-group">
<label for="title">Title:</label>
<input type="text" class="form-control" id="title" required />

<label for="author">Author:</label>
<input type="text" class="form-control" id="author" required />

<label for="pages">Pages:</label>
<input type="number" class="form-control" id="pages" required />

<input type="checkbox" class="form-check-input" id="check" />
<label for="check" class="form-check-label">Read</label>

<div id="demo" class="collapse">
<div class="form-group">
<label for="title">Title:</label>
<input
type="title"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="author"
class="form-control"
id="author"
name="author"
required
/>
<label for="pages">Pages:</label>
<input
type="number"
class="form-control"
id="pages"
name="pages"
required
/>
<label class="form-check-label">
<input
type="checkbox"
class="form-check-input"
id="check"
value=""
/>Read
</label>
<input
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
/>
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit()"
/>
<!-- check this -->
</div>
</div>
</div>

<table class="table" id="display">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Author</th>
<th>Number of Pages</th>
<th>Read</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

<table class="table" id="display">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Author</th>
<th>Number of Pages</th>
<th>Read</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</main>
<script src="script.js"></script>
</body>
</html>
76 changes: 47 additions & 29 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ window.addEventListener("load", function (e) {

function populateStorage() {
if (myLibrary.length == 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true);
let book2 = new Book(
"The Old Man and the Sea",
"Ernest Hemingway",
Expand All @@ -29,32 +29,52 @@ const check = document.getElementById("check");
//via Book function and start render function
function submit() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
!title.value ||
!author.value ||
!pages.value ||
Number(pages.value) <= 0 ||
Number.isNaN(Number(pages.value))
) {
alert("Please fill all fields!");
alert("Please fill all fields with valid input!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(
title.value,
author.value,
Number(pages.value),
check.checked
);
myLibrary.push(book);
render();

//clears the form for new entries
title.value = "";
author.value = "";
pages.value = "";
check.checked = false;
}
}

function Book(title, author, pages, check) {
this.title = title;
this.author = author;
this.pages = pages;
this.pages = Number(pages);
this.check = check;
}
function alertDeleteToast(message) {
const toast = document.getElementById("toast");
toast.innerHTML = message;
toast.classList.add("visible");

setTimeout(() => {
toast.classList.remove("visible");
}, 4000);
}
function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -71,33 +91,31 @@ function render() {
pagesCell.innerHTML = myLibrary[i].pages;

//add and wait for action for read/unread button
let changeBut = document.createElement("button");
changeBut.id = i;
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
}
changeBut.innerText = readStatus;
let changeBtn = document.createElement("button");
changeBtn.className = "btn btn-success";
wasReadCell.appendChild(changeBtn);

changeBut.addEventListener("click", function () {
let readStatus = myLibrary[i].check ? "Yes" : "No";
changeBtn.innerText = readStatus;

changeBtn.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
render();
});

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
let deleteBtn = document.createElement("button");
deleteBtn.className = "btn btn-warning";
deleteBtn.innerHTML = "Delete";
deleteCell.appendChild(deleteBtn);

deleteBtn.addEventListener("click", function () {
const deleteTitle = myLibrary[i].title;
myLibrary.splice(i, 1);
render();
alertDeleteToast(
`You've deleted title: <br> <strong>${deleteTitle}</strong>`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Since this argument is to be assigned to .innerHTML of an element, best practice is to first escape
all special characters in deleteTitle to prevent corruption of the display or HTML injection.

(No change needed)

);
});
}
}
83 changes: 79 additions & 4 deletions debugging/book-library/style.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,94 @@
.jumbotron {
padding: 1.5rem 2rem;
margin-bottom: 1rem;
text-align: center;
}

.jumbotron h2 {
font-size: 1.5rem;
font-weight: 300;
margin-top: 0.5rem;
}

.form-group {
width: 400px;
height: 300px;
align-self: left;
padding-left: 20px;
padding-left: 50px;
}

#check {
margin-left: 0;
margin-top: 10px;
}

.btn {
display: block;
}

.form-control {
border-style: solid;
border-color: lightslategrey;
}

.form-check-label {
padding-left: 20px;
margin: 5px 0px 5px 0px;
}

button.btn-info {
margin: 20px;
.btn-info {
background-color: blue;
border-color: blue;
color: #fff;
margin: 20px 20px 20px 50px;
}

.btn-success {
background-color: #0d4a0d;
border-color: #0d4a0d;
color: #fff;
}

.btn-success:hover,
.btn-success:focus {
background-color: #1f6e1f;
border-color: #1f6e1f;
color: #fff;
}

.btn-warning {
background-color: #9f6000;
border-color: #9f6000;
color: #fff;
}

.btn-warning:hover,
.btn-warning:focus {
background-color: #b76e01;
border-color: #b76e01;
color: #fff;
}

/* for delete alert */
.toast {
position: fixed;
top: 130px;
left: 50%;
font-size: 1rem;
transform: translateX(-50%);
background: #a84600;
color: white;
min-width: 300px;
width: fit-content;
white-space: normal;
word-wrap: break-word;
text-align: center;
padding: 10px 15px;
border-radius: 5px;
opacity: 0;
transition: opacity 0.3s ease;
pointer-events: none;
}

.toast.visible {
opacity: 1;
}
Loading