Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
32cd65e
Update pull_request_template.md (#223)
cjyuan May 6, 2025
f71f87a
Fix the link to Style Guide in PR template
cjyuan Jul 8, 2025
11a9611
update index.html
zohrehKazemianpour Jul 24, 2025
a5245d8
fix: use author name instead of title
zohrehKazemianpour Jul 24, 2025
483a1e5
Fix render function bugs: missing parenthesis, variable mismatch, and…
zohrehKazemianpour Jul 28, 2025
0a74951
Fix form submission and rendering issues
zohrehKazemianpour Jul 28, 2025
d9a959e
feat: clear form after successful book submission
zohrehKazemianpour Jul 28, 2025
4b35ce9
fix :delBut eventListener to "click" instead of "clicks"
zohrehKazemianpour Jul 28, 2025
ced4f5c
refactor: replace button IDs with data-index attributes for Read/Dele…
zohrehKazemianpour Jul 28, 2025
3cd97df
Fix incorrect logic for checkbox read status
zohrehKazemianpour Jul 28, 2025
61a36b8
fix(html): resolve W3C validation errors: - Add lang attribute to htm…
zohrehKazemianpour Aug 4, 2025
e5aebaf
fix: convert page numbers to number data type
zohrehKazemianpour Aug 4, 2025
0ee09f5
feat: add validation for page numbers and trim whitespace
zohrehKazemianpour Aug 4, 2025
ebd3fc1
refactor: optimize table clearing by using innerHTML instead of loop
zohrehKazemianpour Aug 4, 2025
6c1803e
Fixed book duplication issue in render() function"
zohrehKazemianpour Aug 4, 2025
fd8786a
Replace innerHTML with textContent for security
zohrehKazemianpour Aug 4, 2025
bb948ae
Refactor: Remove redundant readStatus variable and combine read-statu…
zohrehKazemianpour Aug 4, 2025
7203bd7
refactor: replace alert() with confirm() before deletion
zohrehKazemianpour Aug 4, 2025
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
10 changes: 5 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

You must title your PR like this:

COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME

For example,

NW4 | Carol Owen | HTML-CSS-Module | Week1
London | May-2025 | Carol Owen | Sprint-1

Complete the task list below this message.
If your PR is rejected, check the task list.
Expand All @@ -18,10 +18,10 @@ If your PR is rejected, check the task list.
Self checklist

- [ ] I have committed my files one by one, on purpose, and for a reason
- [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
- [ ] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
- [ ] I have tested my changes
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
- [ ] My changes meet the [requirements](./README.md) of this task
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/reviewing/style-guide/)
- [ ] My changes meet the requirements of this task

## Changelist

Expand Down
58 changes: 12 additions & 46 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +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"
/>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
Expand All @@ -30,43 +24,15 @@ <h1>Library</h1>
<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
/>
<input type="text" class="form-control" id="title" name="title" required>
<label for="author">Author:</label>
<input type="text" class="form-control" id="author" name="author" required>
<label for="pages">Pages:</label>
<input
type="number"
class="form-control"
id="pages"
name="pages"
required
/>
<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
<input type="checkbox" class="form-check-input" id="check" value="">Read
</label>
<input
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
/>
<input type="submit" value="Submit" id="submit" class="btn btn-primary">
</div>
</div>

Expand Down
79 changes: 40 additions & 39 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ window.addEventListener("load", function (e) {
});

function populateStorage() {
if (myLibrary.length == 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book2 = new Book(
"The Old Man and the Sea",
"Ernest Hemingway",
"127",
true
);
if (myLibrary.length === 0) {
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true);
let book2 = new Book("The Old Man and the Sea", "Ernest Hemingway", 127, true);
myLibrary.push(book1);
myLibrary.push(book2);
render();
}
}

Expand All @@ -29,20 +23,32 @@ 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.trim() === "" ||
author.value.trim() === "" ||
pages.value === ""
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
render();
}
}
if (isNaN(parseInt(pages.value)) || parseInt(pages.value) <= 0) {
alert("Please enter a valid positive number for pages!");
return false;
}
let book = new Book(title.value.trim(), author.value.trim(), parseInt(pages.value), check.checked);
myLibrary.push(book);
}

const submitBtn = document.getElementById("submit");
submitBtn.addEventListener("click", function (e) {
e.preventDefault();
submit();
render();
title.value = "";
author.value = "";
pages.value = "";
check.checked = false;
});

function Book(title, author, pages, check) {
this.title = title;
this.author = author;
Expand All @@ -54,49 +60,44 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
table.deleteRow(n);
}
let tbody = table.querySelector('tbody')
tbody.innerHTML = "";
//insert updated row and cells
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
let row = table.insertRow(1);
let row = tbody.insertRow();
let titleCell = row.insertCell(0);
let authorCell = row.insertCell(1);
let pagesCell = row.insertCell(2);
let wasReadCell = row.insertCell(3);
let deleteCell = row.insertCell(4);
titleCell.innerHTML = myLibrary[i].title;
authorCell.innerHTML = myLibrary[i].author;
pagesCell.innerHTML = myLibrary[i].pages;
titleCell.textContent = myLibrary[i].title;
authorCell.textContent = myLibrary[i].author;
pagesCell.textContent = myLibrary[i].pages;

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

changeBut.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
const index = parseInt(this.dataset.index);
myLibrary[index].check = !myLibrary[index].check;
render();
});

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
let delBut = document.createElement("button");
delBut.dataset.index = i;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
delBut.addEventListener("click", function () {
const index = parseInt(this.dataset.index);
if(confirm(`Are you sure you want to delete ${myLibrary[index].title}`))
myLibrary.splice(index, 1);
render();
});
}
Expand Down