Skip to content

Commit c808c0d

Browse files
committed
add if statement to check alreadyread books and set their background to meet color condition
1 parent a1af7d4 commit c808c0d

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

Sprint-3/reading-list/script.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@ const books = [
2222
bookCoverImage: "https://blackwells.co.uk/jacket/l/9780135957059.jpg",
2323
},
2424
];
25-
function readingList(bookArray){
26-
const contentEl = document.getElementById("content");
27-
const ulListEl = document.getElementById("reading-list");
2825

29-
for (const book of bookArray){
30-
const li = document.createElement("li");
31-
ulListEl.appendChild(li);
32-
li.textContent = `${book.title} by ${book.author}`;
33-
const img = document.createElement('img');
34-
li.appendChild(img)
35-
img.src = book.bookCoverImage;
36-
}
26+
function readingList(bookArray) {
27+
const contentEl = document.getElementById("content");
28+
const ulListEl = document.getElementById("reading-list");
29+
30+
for (const book of bookArray) {
31+
const li = document.createElement("li");
32+
ulListEl.appendChild(li);
33+
li.textContent = `${book.title} by ${book.author}`;
34+
const img = document.createElement("img");
35+
li.appendChild(img);
36+
img.src = book.bookCoverImage;
37+
38+
if (book.alreadyRead) {
39+
li.style.backgroundColor = "green";
40+
} else {
41+
li.style.backgroundColor = "red";
42+
}
43+
}
3744
}
3845
readingList(books);
3946
// Render the list of books on the page. Each book should have a title, author and image and a background colour that is set dependent on whether we have read the book or not.

0 commit comments

Comments
 (0)