Skip to content

Commit 9771eeb

Browse files
committed
Build reading list app with dynamic rendering, images, and conditional styling
1 parent 96d077b commit 9771eeb

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Sprint-3/reading-list/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="stylesheet" href="style.css" />
7-
<title>Title here</title>
7+
<title>Reading List</title>
88
</head>
99
<body>
1010
<div id="content">

Sprint-3/reading-list/script.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,31 @@ const books = [
2121
},
2222
];
2323

24+
const list = document.getElementById("reading-list");
25+
26+
books.forEach((book) => {
27+
const li = document.createElement("li");
28+
29+
// Add title + author (text must exist for tests)
30+
li.textContent = `${book.title} by ${book.author}`;
31+
32+
// Create image
33+
const img = document.createElement("img");
34+
img.src = book.bookCoverImage;
35+
36+
// IMPORTANT: ensures exact HTML match for tests
37+
img.setAttribute("src", book.bookCoverImage);
38+
39+
// Add image to list item
40+
li.appendChild(img);
41+
42+
// Set background colour based on read status
43+
if (book.alreadyRead) {
44+
li.style.backgroundColor = "green";
45+
} else {
46+
li.style.backgroundColor = "red";
47+
}
48+
49+
// Add to page
50+
list.appendChild(li);
51+
});

0 commit comments

Comments
 (0)