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
5 changes: 3 additions & 2 deletions Sprint-3/reading-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<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">
<ul id="reading-list"></ul>
<ul id="reading-list">
</ul>
</div>
<script src="script.js"></script>
</body>
Expand Down
5 changes: 4 additions & 1 deletion Sprint-3/reading-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"jest": "^30.2.0"
}
}
20 changes: 20 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ const books = [
},
];

function readingList() {
const unorderedList = document.querySelector("#reading-list");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a good name for the variable? Another thing, what if you code cannot find this dom element? How can you guard your function against it?

for (const book of books) {
const newList = document.createElement("li");
const newImage = document.createElement("img");
const { title, author, bookCoverImage } = book;
Copy link
Contributor

Choose a reason for hiding this comment

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

You could do something more interesting. Just fyi

  for (const {title, author, bookCoverImage, alreadyRead} of books) {}

newImage.src = bookCoverImage;
const paragraph = document.createElement("p");
paragraph.textContent = `${title} by ${author}`;
newList.append(paragraph, newImage);
if (book.alreadyRead) {
newList.classList.add("read");
} else {
newList.classList.add("notRead");
}

unorderedList.appendChild(newList);
}
}
readingList();
6 changes: 3 additions & 3 deletions Sprint-3/reading-list/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ describe("Reading list", () => {
const firstLi = page.window.document.querySelector(
"#reading-list > :first-child"
);
expect(firstLi).toHaveStyle({ backgroundColor: "red" });
expect(firstLi).toHaveClass("notRead");

const secondLi = page.window.document.querySelector(
"#reading-list > :nth-child(2)"
);
expect(secondLi).toHaveStyle({ backgroundColor: "green" });
expect(secondLi).toHaveClass("read");

const thirdLi = page.window.document.querySelector(
"#reading-list > :nth-child(3)"
);
expect(thirdLi).toHaveStyle({ backgroundColor: "green" });
expect(thirdLi).toHaveClass("read");
});
});
21 changes: 21 additions & 0 deletions Sprint-3/reading-list/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ body {
background: #87ca8a;
}

#reading-list li {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 10px;
margin-bottom: 10px;
}

.read {
background-color: #87ca8a;
}

.notRead {
background-color: red;
}

#reading-list img {
max-width: 100%;
height: auto;
display: block;
}
@media screen and (min-width: 992px) {
.navbar-brand > img {
max-height: 80px;
Expand Down