Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions Book_Library/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const addBook = (e) => {
e.preventDefault();

const book = getBookInfo();

if (!book) return;
book.id = crypto.randomUUID()
myLibrary.addBook(book);
createCard(book);
Expand All @@ -43,7 +43,14 @@ const getBookInfo = () => {
const bookAuthor = document.getElementById("book-author").value;
const bookIsRead = document.getElementById("book-is-read").value;

return new Book(bookTitle, bookAuthor, bookIsRead);
if (myLibrary.books.some(
(b) => b.title === bookTitle
)) {
alert("Book already exists!");
return null;
} else {
return new Book(bookTitle, bookAuthor, bookIsRead);
}
}

const createCard = (book) => {
Expand Down
8 changes: 7 additions & 1 deletion Book_Library/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ body {
.book-info {
font-size: var(--font-size-20);
font-weight: var(--font-weight-bold);
height: 150px;
}

.book-info p {
text-wrap: wrap;
text-align: center;
}

.book-card {
Expand All @@ -99,7 +105,7 @@ body {
height: 300px;
justify-content: space-evenly;
padding: 20px;
gap: 35px;
gap:25px;
}

.books-operations-buttons {
Expand Down