Skip to content
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

CYF-ITP-South Africa | Serna Malala | Module-Data-Groups | Week 3 Reading List Display #285

Open
wants to merge 3 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
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
30 changes: 30 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,33 @@ const books = [
},
];

const readingList = document.getElementById("reading-list");
function populateBooks(bookArray) {

bookArray.forEach(item => {

const listItem = document.createElement("li");
const div = document.createElement("div");
const title = document.createElement("h2");
const author = document.createElement("h3");
Comment on lines +31 to +32
Copy link

Choose a reason for hiding this comment

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

How do you determine title is level 2 heading and author is level 3 heading?

Have you considered marking them as <div class="title"> and <div class="author"> and then use CSS to style the them accordingly?

Copy link
Author

Choose a reason for hiding this comment

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

hmm well I did not really think that out to be honest, knowing the rules with using headings I should have used a different element

const image = document.createElement("img");
let colour = "red";
if (item.alreadyRead === true) {
colour = "green";
}
title.textContent = item.title;
author.textContent = item.author;
image.src = item.bookCoverImage;
readingList.style.textAlign = "center";
div.style.backgroundColor = colour;
div.style.maxWidth = "500px";
image.style.width = "200px";
Comment on lines +41 to +44
Copy link

Choose a reason for hiding this comment

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

Why not style these elements in style.css?

Copy link
Author

Choose a reason for hiding this comment

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

I wanted to play around with the DOM manipulation in javascript but yes, those can definitely be hardcoded in the CSS

readingList.appendChild(listItem);
listItem.appendChild(div);
div.appendChild(title);
div.appendChild(author);
div.appendChild(image);
});
}

populateBooks(books);