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
50 changes: 37 additions & 13 deletions Sprint-3/reading-list/script.js

Choose a reason for hiding this comment

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

In you readList function, you did this: function readingList(bookArray) and then you came out of the function to loop over books when you did this: for (const singleBook of books). You ignored your function parameter and hardcoded books. The problem with this is if someone passes over a different array, your function would you it. You need to loop over your function parameter, not books array.

Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
// for the tests, do not modify this array of books
const books = [
{
title: "The Design of Everyday Things",
author: "Don Norman",
title: 'The Design of Everyday Things',
author: 'Don Norman',
alreadyRead: false,
bookCoverImage: "https://blackwells.co.uk/jacket/l/9780465050659.jpg",
bookCoverImage: 'https://blackwells.co.uk/jacket/l/9780465050659.jpg',
},
{
title: "The Most Human Human",
author: "Brian Christian",
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",
'https://images-na.ssl-images-amazon.com/images/I/41m1rQjm5tL._SX322_BO1,204,203,200_.jpg',
},
];

const content = document.getElementById("content");
const container = document.getElementById("reading-list");

console.log("Container Element Found:", container);

function readingList(bookArray) {
for (const singleBook of books) {
const bookListItem = document.createElement("li");
const titleElement = document.createElement("h3");
const authorElement = document.createElement("p");
const coverImage = document.createElement("img");

titleElement.textContent = singleBook.title;
authorElement.textContent = `Author: ${singleBook.author}`;

coverImage.setAttribute("src", singleBook.bookCoverImage);

if (singleBook.alreadyRead === true) {
bookListItem.style.backgroundColor = "#5aec7cff";
} else {
bookListItem.style.backgroundColor = "#c00d1cff";
}

bookListItem.appendChild(titleElement);
bookListItem.appendChild(authorElement);
bookListItem.appendChild(coverImage);
container.appendChild(bookListItem);
}
}

readingList(books);
Empty file added reading-list.md
Empty file.
Loading