-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (42 loc) · 1.28 KB
/
script.js
File metadata and controls
45 lines (42 loc) · 1.28 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
const titleEl = document.querySelector("title");
titleEl.textContent = "Reading list app";
// 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(bookArray) {
const contentEl = document.getElementById("content");
const ulListEl = document.getElementById("reading-list");
for (const book of bookArray) {
const li = document.createElement("li");
ulListEl.appendChild(li);
li.textContent = `${book.title} by ${book.author}`;
const img = document.createElement("img");
li.appendChild(img);
img.src = book.bookCoverImage;
if (book.alreadyRead) {
li.style.backgroundColor = "green";
} else {
li.style.backgroundColor = "red";
}
}
}
readingList(books);