-
-
Notifications
You must be signed in to change notification settings - Fork 41
NW-6 | AREEB-SATTAR | JS2| [TECH ED] Reading List| WEEK-3 #221
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
<!DOCTYPE > | ||
<!DOCTYPE> | ||
<html lang="en_US"> | ||
<head> | ||
<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> | ||
</head> | ||
<body> | ||
<div id="content"> | ||
<ul id="reading-list"></ul> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<script defer src="script.js"></script> | ||
<title>Reading List</title> | ||
</head> | ||
|
||
<body> | ||
<div id="content"> | ||
<ul id="reading-list"></ul> | ||
</div> | ||
|
||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
function readingList(books) { | ||
const readingList = document.getElementById("reading-list"); | ||
|
||
for (const item of books) { | ||
const list = document.createElement("li"); | ||
|
||
list.setAttribute("class", item.alreadyRead ? "teal" : "red"); | ||
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'm going to be really picky, but hopefully this is a useful note! As much as possible, it's good to keep your styling separate from logic. You could use class names like "read" and "unread", then only use CSS to decide what the colour should be. This is really useful for modifying your site in the future, as all colour choices are together in the CSS. There is also a scenario where your site might have different themes, for example, a light and dark mode. The colours for read and unread books might not always be the same in each mode. 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. That makes sense, I will keep that in mind, Thank you |
||
|
||
const p = document.createElement("p"); | ||
p.innerText = `${item.title} by ${item.author}`; | ||
|
||
readingList.appendChild(list); | ||
list.appendChild(p); | ||
|
||
const image = document.createElement("img"); | ||
image.src = item.bookCoverImage; | ||
list.appendChild(image); | ||
} | ||
} | ||
|
||
// for the tests, do not modify this array of books | ||
const books = [ | ||
{ | ||
|
@@ -21,3 +41,4 @@ const books = [ | |
}, | ||
]; | ||
|
||
readingList(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.
Nice use of the
defer
attribute!