Skip to content

ZA Cape Town | ITP-May-2025 | Dawud Vermeulen | Sprint 3 | Reading-List #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ const books = [
},
];

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

books.forEach(book => {
const listItem = document.createElement('li'); // for each book, create a list item
listItem.style.backgroundColor = book.alreadyRead ? 'green' : 'red'; // set background color based on alreadyRead status
Copy link

Choose a reason for hiding this comment

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

Code works as intended. However, it's recommended to use css classes to modify the styles. You don't have to change the code here tho.


const titleAuthor = document.createElement("p"); // create a paragraph for title and author
titleAuthor.textContent = `${book.title} by ${book.author}`; // set text content to "title by author"

const coverImage = document.createElement("img");
coverImage.src = book.bookCoverImage;
//coverImage.alt = `Cover of ${book.title}`; // this make the test fail

listItem.appendChild(titleAuthor);
listItem.appendChild(coverImage);

readingListElement.appendChild(listItem);
});
}

document.addEventListener('DOMContentLoaded', () => {
readingList(books);
});