Skip to content

Commit ecd9d79

Browse files
committed
V2.3 week2
Completed the 3rd exercise in mandatory folder.
1 parent a7f38ec commit ecd9d79

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Week-2/Homework/mandatory/2-exercises/exercises.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,43 @@ function exerciseTwo(shopping) {
8484
The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com/
8585
**/
8686
function exerciseThree(books) {
87+
88+
let content = document.querySelector("#content");
89+
let ul=document.createElement("ul");
90+
ul.className="ulList";
91+
content.appendChild(ul);
92+
// created an array of links for images source.
93+
var imageSource=["https://m.media-amazon.com/images/I/416Hql52NCL.jpg",
94+
"https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1295465264l/8884400.jpg",
95+
"https://images-na.ssl-images-amazon.com/images/I/51cUVaBWZzL.jpg" ]
96+
97+
98+
for(let i=0;i<books.length;i++)
99+
{
100+
var p=document.createElement("p");
101+
var li=document.createElement("li");
102+
li.className="liItem";
103+
104+
p.textContent+=books[i].title +"-" + books[i].author;
105+
li.appendChild(p);
106+
107+
108+
let img=document.createElement("img");
109+
img.className="imgDimension";
110+
111+
img.src=imageSource[i];
112+
img.alt= books[i].title +"-" + books[i].author;
113+
114+
li.appendChild(img);
115+
116+
if(books[i].alreadyRead)
117+
li.style.backgroundColor="green";
118+
else
119+
li.style.backgroundColor="red";
120+
121+
ul.appendChild(li);
122+
123+
}
87124
}
88125

89126
//

Week-2/Homework/mandatory/2-exercises/style.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ body {
151151
background: #87ca8a
152152
}
153153

154+
155+
156+
157+
/* ----------------------------- */
158+
/* Adding some classes to make javascript neat */
159+
160+
.ulList
161+
{
162+
display: flex;
163+
justify-content: space-around;
164+
list-style-type:none ;
165+
}
166+
167+
.liItem
168+
{
169+
padding:1rem;
170+
width:27vw;
171+
}
172+
173+
.imgDimension
174+
{
175+
width:200px;
176+
height:300px;
177+
}
178+
179+
180+
181+
182+
183+
184+
185+
154186
@media screen and (min-width: 992px) {
155187

156188
.navbar-brand > img {

0 commit comments

Comments
 (0)