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
51 lines (43 loc) · 1.3 KB
/
Copy pathscript.js
File metadata and controls
51 lines (43 loc) · 1.3 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
// 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",
},
];
const list = document.getElementById("reading-list");
books.forEach((book) => {
const li = document.createElement("li");
// Add title + author (text must exist for tests)
li.textContent = `${book.title} by ${book.author}`;
// Create image
const img = document.createElement("img");
img.src = book.bookCoverImage;
// IMPORTANT: ensures exact HTML match for tests
img.setAttribute("src", book.bookCoverImage);
// Add image to list item
li.appendChild(img);
// Set background colour based on read status
if (book.alreadyRead) {
li.style.backgroundColor = "green";
} else {
li.style.backgroundColor = "red";
}
// Add to page
list.appendChild(li);
});