File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 < meta charset ="utf-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < link rel ="stylesheet " href ="style.css " />
7- < title > Title here </ title >
7+ < title > Reading List </ title >
88 </ head >
99 < body >
1010 < div id ="content ">
Original file line number Diff line number Diff line change @@ -21,3 +21,31 @@ const books = [
2121 } ,
2222] ;
2323
24+ const list = document . getElementById ( "reading-list" ) ;
25+
26+ books . forEach ( ( book ) => {
27+ const li = document . createElement ( "li" ) ;
28+
29+ // Add title + author (text must exist for tests)
30+ li . textContent = `${ book . title } by ${ book . author } ` ;
31+
32+ // Create image
33+ const img = document . createElement ( "img" ) ;
34+ img . src = book . bookCoverImage ;
35+
36+ // IMPORTANT: ensures exact HTML match for tests
37+ img . setAttribute ( "src" , book . bookCoverImage ) ;
38+
39+ // Add image to list item
40+ li . appendChild ( img ) ;
41+
42+ // Set background colour based on read status
43+ if ( book . alreadyRead ) {
44+ li . style . backgroundColor = "green" ;
45+ } else {
46+ li . style . backgroundColor = "red" ;
47+ }
48+
49+ // Add to page
50+ list . appendChild ( li ) ;
51+ } ) ;
You can’t perform that action at this time.
0 commit comments