forked from CodeYourFuture/Module-Data-Groups
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (56 loc) · 1.86 KB
/
script.js
File metadata and controls
66 lines (56 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// for the tests, do not modify this array of books
const books = [
{
title: "The Design of Everyday Things",
author: "Don Norman",
alreadyRead: false,
bookCoverImage: "https://blackwells.co.uk/jacket/l/9780465050659.jpg",
},
{
title: "The Most Human Human",
author: "Brian Christian",
alreadyRead: true,
bookCoverImage:
"https://images-na.ssl-images-amazon.com/images/I/41m1rQjm5tL._SX322_BO1,204,203,200_.jpg",
},
{
title: "The Pragmatic Programmer",
author: "Andrew Hunt",
alreadyRead: true,
bookCoverImage: "https://blackwells.co.uk/jacket/l/9780135957059.jpg",
},
];
function readingList() {
const orderedList = document.querySelector("#reading-list");
// Base condition: check if books array is empty
if (!books || books.length === 0) {
const emptyMessage = document.createElement("li");
emptyMessage.className = "empty-message";
emptyMessage.textContent =
"No books in your reading list yet. Add some books to get started!";
orderedList.appendChild(emptyMessage);
return;
}
for (const book of books) {
const listItem = document.createElement("li");
const bookImage = document.createElement("img");
bookImage.src = book.bookCoverImage;
bookImage.alt = "Book cover for " + book.title;
const bookInfo = document.createElement("p");
bookInfo.textContent = book.title + " by " + book.author;
const statusBadge = document.createElement("span");
statusBadge.className = "status-badge";
if (book.alreadyRead) {
listItem.classList.add("read");
statusBadge.textContent = "✓";
} else {
listItem.classList.add("notRead");
statusBadge.textContent = "○";
}
listItem.appendChild(bookImage);
listItem.appendChild(bookInfo);
listItem.appendChild(statusBadge);
orderedList.appendChild(listItem);
}
}
readingList();