Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-3/reading-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Reading List App</title>
</head>
<body>
<div id="content">
Expand Down
44 changes: 44 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// for the tests, do not modify this array of books


const books = [
{
title: "The Design of Everyday Things",
Expand All @@ -21,3 +23,45 @@ const books = [
},
];




/**
* Render the reading list into the DOM.
* Expects an element with id="reading-list" in index.html (e.g. <ul id="reading-list"></ul>)
*/




function readingList() {
const unorderedList = document.querySelector("#reading-list");

books.forEach((book) => {
const li = document.createElement("li");

// Image first
const img = document.createElement("img");
img.src = book.bookCoverImage;
img.alt = `${book.title} by ${book.author} — book cover`;
img.loading = "lazy";
li.appendChild(img);

// Text
const p = document.createElement("p");
p.innerText = `${book.title} by ${book.author}`;
li.appendChild(p);

// Inline background color (Jest reads this)
li.style.backgroundColor = book.alreadyRead ? "red" : "green";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the reverse logic as to the example shown in the Readme file in the task.


unorderedList.appendChild(li);
Comment on lines +43 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is exactly how you would accomplish this however, this doesn't match the example given in the Readme.md where book title comes first and then the image.

});
}

// ---- FIX FOR JSDOM ----
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", readingList);
} else {
readingList();
}