We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 610f0ce commit 6acbd7cCopy full SHA for 6acbd7c
debugging/book-library/script.js
@@ -37,17 +37,24 @@ function submit() {
37
alert("Please fill all fields!");
38
return false;
39
} else {
40
+ const alreadyExists = myLibrary.some(
41
+ (book) => book.title === title.value);
42
+ if (alreadyExists) {
43
+ alert("This book is already in your library!");
44
+ return;
45
+ }
46
47
let book = new Book(title.value, author.value, pages.value, check.checked);
48
myLibrary.push(book);
49
render();
-
50
+
51
//clear the form after submit
52
title.value = "";
53
author.value = "";
54
pages.value = "";
55
check.checked = false;
56
}
-}
57
58
59
function Book(title, author, pages, check) {
60
this.title = title;
0 commit comments