Skip to content

London/May 2025/Alexandru Pocovnicu/Sprint3/reading list #634

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 5 commits 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
42 changes: 41 additions & 1 deletion 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
// for the tests, do not modify this array of books.


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

//
//create <li> elements
//add the content of the objects to the <li>s
//extract each object from the array
//append the <li>s to the <ul> tag in html



function displaybooks(book) {
const bookTitle = document.createElement("p");
bookTitle.textContent = book.title;
const bookAuthor = document.createElement("p");
bookAuthor.textContent = book.author;

const titleAuthor = document.createElement("p");
titleAuthor.textContent =
bookTitle.textContent + " by " + bookAuthor.textContent;

const image = document.createElement("img");
image.src = book.bookCoverImage;

const allTogether = document.createElement("li");
allTogether.appendChild(titleAuthor);
allTogether.appendChild(image);

if (book.alreadyRead === false) {
allTogether.style.backgroundColor = "red";
} else {
allTogether.style.backgroundColor = "green";
}

document.querySelector("#reading-list").appendChild(allTogether);
}

for (let i = 0; i < books.length; i++) {
displaybooks(books[i]);
}

Loading