-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not style these elements in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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