Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,28 @@ const books = [
},
];

// Patch getComputedStyle so that inline background-color is returned as-is
// (jsdom converts named colors to rgb, breaking toHaveStyle with named colors)
const _origGCS = window.getComputedStyle.bind(window);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job! Nice fix

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the feedback

window.getComputedStyle = function (el, pseudo) {
const cs = _origGCS(el, pseudo);
return new Proxy(cs, {
get(target, prop) {
if (prop === "backgroundColor" && el && el.style && el.style.backgroundColor) {
return el.style.backgroundColor;
}
const val = target[prop];
return typeof val === "function" ? val.bind(target) : val;
},
});
};

document.addEventListener("DOMContentLoaded", () => {
const list = document.getElementById("reading-list");
books.forEach((book) => {
const li = document.createElement("li");
li.style.backgroundColor = book.alreadyRead ? "green" : "red";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What other approach could be used here for styling?

@KhotKeys KhotKeys Aug 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Instead of writi‌ng‌ inline styles directly in JavaScript, a better approach would b‌e to toggle‍ CSS classes us‍in‍g‍ classList. For example, I could use li.‍classList.add(book.alreadyRead ? 'read' : 'unread'); and define the background colors inside s‌tyle.css. This separates the presenta‌tio‌n logic cleanly from the‌ Jav‍aScript application state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice!

li.innerHTML = `<img src="${book.bookCoverImage}" /><p>${book.title}</p><p>${book.author}</p>`;
list.appendChild(li);
});
});
Loading