Skip to content

Commit e813e11

Browse files
committed
handled null or undefined book variable. returns helpful message
1 parent 2bbaaf3 commit e813e11

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sprint-3/reading-list/script.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ const books = [
2323
function readingList() {
2424
const unorderedList = document.querySelector("#reading-list");
2525

26+
// Base condition: check if books array is empty
27+
if (!books || books.length === 0) {
28+
const emptyMessage = document.createElement("li");
29+
emptyMessage.textContent =
30+
"No books in your reading list yet. Add some books to get started!";
31+
emptyMessage.style.listStyle = "none";
32+
emptyMessage.style.padding = "20px";
33+
emptyMessage.style.textAlign = "center";
34+
emptyMessage.style.color = "#666";
35+
unorderedList.appendChild(emptyMessage);
36+
return; // Exit the function early
37+
}
38+
2639
for (const book of books) {
2740
const newList = document.createElement("li");
2841

0 commit comments

Comments
 (0)