-
-
Notifications
You must be signed in to change notification settings - Fork 226
London|ITP-Jan-2026 |Alexandru Pocovnicu | Sprint 2 | Book library #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexandru-pocovnicu
wants to merge
30
commits into
CodeYourFuture:main
Choose a base branch
from
alexandru-pocovnicu:book-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−56
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
026ab7c
Fix: Corrected variable name from 'library' to 'myLibrary' in submit …
alexandru-pocovnicu ba1e8fc
Fix: Corrected syntax error in the render function's for loop
alexandru-pocovnicu 9152461
Fix: Corrected button creation and event listener for delete function…
alexandru-pocovnicu 2be9382
Fix: Corrected validation check for author input in submit function
alexandru-pocovnicu 2ce8154
Fix: Corrected logic for book read status in submit function
alexandru-pocovnicu e160341
Fix: Corrected event listener type for delete button in render function
alexandru-pocovnicu 62672c3
Fix: Corrected author value assignment in book creation within submit…
alexandru-pocovnicu 31236b1
Fix: Corrected book creation to use checked state for read status in …
alexandru-pocovnicu 88c944d
Fix: Corrected read status display logic in render function
alexandru-pocovnicu e9a419f
Fix: Added validation for pages input in submit function
alexandru-pocovnicu 9e5e015
Fix: Added language attribute to html tag and updated title in index.…
alexandru-pocovnicu 6eef9d9
Fix: Standardized HTML syntax and formatting in index.html
alexandru-pocovnicu cc880b1
delete trailing slash
alexandru-pocovnicu 0a0dcf3
Fix: Corrected input types for title and author fields in index.html
alexandru-pocovnicu 8e1e374
Fix: Corrected meta tag and input element syntax in index.html
alexandru-pocovnicu 02d14fc
Fix: Removed unnecessary align-self property from .form-group in styl…
alexandru-pocovnicu ca4167d
Fix: Corrected self-closing tags and standardized HTML syntax in inde…
alexandru-pocovnicu 866e223
Fix: Remove unnecessary render call on window load and clean up white…
alexandru-pocovnicu b4fe64c
set time delay for alert message
alexandru-pocovnicu 3c8c704
Rename button variables for clarity
alexandru-pocovnicu e9452d6
Fix: Remove unnecessary IDs from buttons in render function
alexandru-pocovnicu e2af0f5
Fix: Replace innerHTML with textContent for safer DOM manipulation in…
alexandru-pocovnicu f72d535
Fix: Update validation checks in submit function for better input han…
alexandru-pocovnicu 07a2811
Fix: Refactor render function to use tbody for better DOM manipulatio…
alexandru-pocovnicu f24b3b1
Fix: Refactor submit function to use trimmed values for better input …
alexandru-pocovnicu c0410cc
Fix: Update pages value handling in submit function for improved inpu…
alexandru-pocovnicu 71af8ec
Fix: Rename input variable references for consistency and clarity in …
alexandru-pocovnicu fff5df5
Fix: Correct pages value type in Book instantiation and update valida…
alexandru-pocovnicu 0e1d107
Fix: Change myLibrary to const and move input variable declarations t…
alexandru-pocovnicu 6f8c193
change if statement with ternary operator
alexandru-pocovnicu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,19 @@ | ||
| let myLibrary = []; | ||
|
|
||
| const myLibrary = []; | ||
| const titleInput = document.getElementById("title"); | ||
| const authorInput = document.getElementById("author"); | ||
| const pagesInput = document.getElementById("pages"); | ||
| const readCheckbox = document.getElementById("check"); | ||
| window.addEventListener("load", function (e) { | ||
| populateStorage(); | ||
| render(); | ||
| }); | ||
|
|
||
| function populateStorage() { | ||
| if (myLibrary.length == 0) { | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); | ||
| let book2 = new Book( | ||
| "The Old Man and the Sea", | ||
| "Ernest Hemingway", | ||
| "127", | ||
| 127, | ||
| true | ||
| ); | ||
| myLibrary.push(book1); | ||
|
|
@@ -20,25 +22,31 @@ function populateStorage() { | |
| } | ||
| } | ||
|
|
||
| const title = document.getElementById("title"); | ||
| const author = document.getElementById("author"); | ||
| const pages = document.getElementById("pages"); | ||
| const check = document.getElementById("check"); | ||
|
|
||
| //check the right input from forms and if its ok -> add the new book (object in array) | ||
| //via Book function and start render function | ||
| function submit() { | ||
| const titleValue = titleInput.value.trim(); | ||
| const authorValue = authorInput.value.trim(); | ||
| const pagesValue = pagesInput.value.trim(); | ||
| const pagesCount = Number(pagesValue); | ||
|
|
||
| if ( | ||
| title.value == null || | ||
| title.value == "" || | ||
| pages.value == null || | ||
| pages.value == "" | ||
| titleValue == "" || | ||
| authorValue == "" || | ||
| pagesValue == "" || | ||
| pagesCount < 0 || | ||
| !Number.isInteger(pagesCount) | ||
| ) { | ||
| alert("Please fill all fields!"); | ||
| return false; | ||
| } else { | ||
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| let book = new Book( | ||
| titleValue, | ||
| authorValue, | ||
| pagesCount, | ||
| readCheckbox.checked | ||
| ); | ||
| myLibrary.push(book); | ||
| render(); | ||
| } | ||
| } | ||
|
|
@@ -51,53 +59,48 @@ function Book(title, author, pages, check) { | |
| } | ||
|
|
||
| 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 tableBody = document.querySelector("tbody"); | ||
| tableBody.innerHTML = ""; | ||
|
|
||
| //insert updated row and cells | ||
| let length = myLibrary.length; | ||
| for (let i = 0; i < length; i++) { | ||
| let row = table.insertRow(1); | ||
| let row = tableBody.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.className = "btn btn-success"; | ||
| wasReadCell.appendChild(changeBut); | ||
| let changeButton = document.createElement("button"); | ||
| changeButton.className = "btn btn-success"; | ||
| wasReadCell.appendChild(changeButton); | ||
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
|
|
||
| changeBut.addEventListener("click", function () { | ||
| myLibrary[i].check == false ? (readStatus = "No") : (readStatus = "Yes"); | ||
| changeButton.textContent = readStatus; | ||
|
Comment on lines
82
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a good opportunity to practice using the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| changeButton.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 deleteButton = document.createElement("button"); | ||
| deleteCell.appendChild(deleteButton); | ||
| deleteButton.className = "btn btn-warning"; | ||
| deleteButton.textContent = "Delete"; | ||
| deleteButton.addEventListener("click", function () { | ||
| const deletedTitle = myLibrary[i].title; | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
| setTimeout(function () { | ||
| alert(`You've deleted title: ${deletedTitle}`); | ||
| }, 500); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| .form-group { | ||
| width: 400px; | ||
| height: 300px; | ||
| align-self: left; | ||
| padding-left: 20px; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expr1 ? expr2 : expr3is an expression that evalutes to the value of eitherexpr2orexpr3dependingon the truthy value of
expr1.Normal use of
? :isvariable = expr1 ? expr2 : expr3;instead of
expr1 ? (variable = expr2) : (variable = expr3);Note:
.checkis a boolean value. You can just use its value directly without comparing it totrueorfalse.