- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
NW6 | NazaninSaedi | BookLibrary-JS3 | Week-1 #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,19 +1,22 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title> </title> | ||
| <title>My Book Library</title> <!-- Added a title for your webpage --> | ||
| <meta | ||
| charset="utf-8" | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0" | ||
| /> | ||
| <!-- Updated script sources to use HTTPS --> | ||
| <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> | ||
| <!-- Updated CSS source to use HTTPS --> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | ||
| /> | ||
| <!-- Included your custom CSS file --> | ||
| <link rel="stylesheet" type="text/css" href="style.css" /> | ||
| </head> | ||
|  | ||
|  | @@ -31,15 +34,15 @@ <h1>Library</h1> | |
| <div class="form-group"> | ||
| <label for="title">Title:</label> | ||
| <input | ||
| type="title" | ||
| type="text" <!-- Corrected input type to "text" --> | ||
| class="form-control" | ||
| id="title" | ||
| name="title" | ||
| required | ||
| /> | ||
| <label for="author">Author: </label> | ||
| <input | ||
| type="author" | ||
| type="text" <!-- Corrected input type to "text" --> | ||
| 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. 👍 | ||
| class="form-control" | ||
| id="author" | ||
| name="author" | ||
|  | @@ -61,12 +64,13 @@ <h1>Library</h1> | |
| value="" | ||
| />Read | ||
| </label> | ||
| <input | ||
| type="submit" | ||
| value="Submit" | ||
| <button | ||
| type="button" <!-- Changed input type to button --> | ||
| 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. Good work. Could you tell me why having type set to submit in this context causes problems? | ||
| class="btn btn-primary" | ||
| onclick="submit();" | ||
| /> | ||
| > | ||
| Submit | ||
| </button> | ||
| </div> | ||
| </div> | ||
|  | ||
|  | @@ -81,13 +85,7 @@ <h1>Library</h1> | |
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| </tr> | ||
| <!-- Removed the default table row --> | ||
| </tbody> | ||
| </table> | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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); // Corrected book title | ||
| 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. 👍 | ||
| let book2 = new Book( | ||
| "The Old Man and the Sea", | ||
| "Ernest Hemingway", | ||
|  | @@ -25,20 +25,20 @@ 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() { | ||
| if ( | ||
| title.value == null || | ||
| title.value == "" || | ||
| author.value == null || // Check for author input | ||
| author.value == "" || | ||
| 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. 👍 | ||
| pages.value == null || | ||
| 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); | ||
| let book = new Book(title.value, author.value, pages.value, check.checked); // Passed author.value instead of title.value | ||
| 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. 👍 | ||
| myLibrary.push(book); | ||
| render(); | ||
| } | ||
| } | ||
|  | @@ -53,11 +53,11 @@ 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-- { | ||
| // Delete old table rows | ||
| for (let n = rowsNumber - 1; n > 0; n--) { // Corrected the loop condition | ||
| 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. 👍 | ||
| table.deleteRow(n); | ||
| } | ||
| //insert updated row and cells | ||
| // Insert updated rows and cells | ||
| let length = myLibrary.length; | ||
| for (let i = 0; i < length; i++) { | ||
| let row = table.insertRow(1); | ||
|  | @@ -70,31 +70,26 @@ function render() { | |
| cell2.innerHTML = myLibrary[i].author; | ||
| cell3.innerHTML = myLibrary[i].pages; | ||
|  | ||
| //add and wait for action for read/unread button | ||
| // Add read/unread button | ||
| let changeBut = document.createElement("button"); | ||
| changeBut.id = i; | ||
| changeBut.className = "btn btn-success"; | ||
| cell4.appendChild(changeBut); | ||
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| let readStatus = myLibrary[i].check ? "No" : "Yes"; // Corrected readStatus assignment | ||
| changeBut.innerHTML = readStatus; | ||
|  | ||
| changeBut.addEventListener("click", function () { | ||
| myLibrary[i].check = !myLibrary[i].check; | ||
| render(); | ||
| }); | ||
|  | ||
| //add delete button to every row and render again | ||
| // Add delete button | ||
| let delButton = document.createElement("button"); | ||
| delBut.id = i + 5; | ||
| cell5.appendChild(delBut); | ||
| delBut.className = "btn btn-warning"; | ||
| delBut.innerHTML = "Delete"; | ||
| delBut.addEventListener("clicks", function () { | ||
| delButton.id = i + 5; // Corrected variable name from delBut to delButton | ||
| 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. 👍 | ||
| cell5.appendChild(delButton); | ||
| delButton.className = "btn btn-warning"; | ||
| delButton.innerHTML = "Delete"; | ||
| delButton.addEventListener("click", function () { // Corrected event name from "clicks" to "click" | ||
| 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. 👍 | ||
| alert(`You've deleted title: ${myLibrary[i].title}`); | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,19 +1,33 @@ | ||
| /* Adjusted styles for the form group */ | ||
| .form-group { | ||
| width: 400px; | ||
| height: 300px; | ||
| align-self: left; | ||
| padding-left: 20px; | ||
| max-width: 400px; | ||
| /* Changed width to max-width for responsiveness */ | ||
| margin: 0 auto; | ||
| /* Center the form group */ | ||
| padding: 20px; | ||
| } | ||
|  | ||
| /* Adjusted styles for buttons */ | ||
| .btn { | ||
| display: block; | ||
| display: inline-block; | ||
| /* Changed display to inline-block for buttons to appear inline */ | ||
| 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. 👍 | ||
| margin-right: 10px; | ||
| /* Added margin-right for spacing between buttons */ | ||
| } | ||
|  | ||
| /* Adjusted styles for form-check-label */ | ||
| .form-check-label { | ||
| display: inline-block; | ||
| /* Changed display to inline-block for checkbox label */ | ||
| 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. Good catch | ||
| padding-left: 20px; | ||
| margin: 5px 0px 5px 0px; | ||
| margin: 5px 20px 5px 0; | ||
| /* Adjusted margin for spacing */ | ||
| } | ||
|  | ||
| /* Adjusted styles for the add new book button */ | ||
| button.btn-info { | ||
| margin: 20px; | ||
| } | ||
| margin: 20px auto; | ||
| /* Center the button */ | ||
| display: block; | ||
| /* Added display: block for full-width button */ | ||
| } | ||
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.
👍