|
53 | 53 | Artist: 'Nick Lowndes' |
54 | 54 | }, |
55 | 55 | id_book_seven: { |
56 | | - author: 'Jim Thompson', |
| 56 | + author: 'Jim Th', |
57 | 57 | language: 'english', |
58 | 58 | name: 'Heed The Thunder', |
59 | 59 | Artist: 'Unknown' |
60 | 60 | }, |
61 | 61 | id_book_eight: { |
62 | 62 | author: 'James Hawes', |
63 | 63 | language: 'english', |
64 | | - name: 'Title: Why You Should Read Kafka Before You Waste Your Life', |
| 64 | + name: 'You Should Read', |
65 | 65 | Artist: 'Steve Snider' |
66 | 66 | }, |
67 | 67 | id_book_nine: { |
|
77 | 77 | Artist: 'Unknown' |
78 | 78 | } |
79 | 79 | }; |
80 | | - |
81 | 80 | const image = { |
82 | | - id_book_one: './imag/id_book_one.jpg', |
83 | | - id_book_two: './imag/id_book_two.jpg', |
84 | | - id_book_three: './imag/id_book_three.jpg', |
85 | | - id_book_four: './imag/id_book_four.jpg', |
86 | | - id_book_five: './imag/id_book_five.jpg', |
87 | | - id_book_six: './imag/id_book_six.jpg', |
88 | | - id_book_seven: './imag/id_book_seven.jpg', |
89 | | - id_book_eight: './imag/id_book_eight.jpg', |
90 | | - id_book_nine: './imag/id_book_nine.jpg', |
91 | | - id_book_ten: './imag/id_book_ten.jpg' |
| 81 | + id_book_one: './image/id_book_one.jpg', |
| 82 | + id_book_two: './image/id_book_two.jpg', |
| 83 | + id_book_three: './image/id_book_three.jpg', |
| 84 | + id_book_four: './image/id_book_four.jpg', |
| 85 | + id_book_five: './image/id_book_five.jpg', |
| 86 | + id_book_six: './image/id_book_six.jpg', |
| 87 | + id_book_seven: './image/id_book_seven.jpg', |
| 88 | + id_book_eight: './image/id_book_eight.jpg', |
| 89 | + id_book_nine: './image/id_book_nine.jpg', |
| 90 | + id_book_ten: './image/id_book_ten.jpg' |
92 | 91 | }; |
93 | | - { |
94 | | - function cover() { |
95 | | - img => (divImgs += `<imag src='${imag}' width = 200>`); |
96 | | - divImgs += '</div>'; |
97 | | - divImgs = divImgs |
98 | | - .split('><') |
99 | | - .join('>,<') |
100 | | - .split(','); |
101 | | - divImgs[0] = "<imag src='./imag/id_book_one.jpg' width = 200>"; |
102 | | - divImgs.pop(); |
103 | | - |
104 | | - for (let i = 0; i < listBooks.length; i++) { |
105 | | - document.body.innerHTML += `${divlistBooks[i]}`; |
106 | | - document.body.innerHTML += `${divImg[i]}`; |
107 | | - } |
108 | | - } |
109 | | - window.addEventListener('load', cover); |
110 | | - } |
111 | | - |
112 | | - let div = document.getElementById('container'); |
| 92 | + const div = document.getElementById('container'); |
113 | 93 |
|
114 | | - let h1Tag = document.createElement('h1'); |
| 94 | + const h1Tag = document.createElement('h1'); |
115 | 95 | h1Tag.innerHTML = 'My Favourite Books'; |
116 | 96 | div.appendChild(h1Tag); |
117 | 97 | h1Tag.className = 'h1Tag'; |
118 | 98 |
|
119 | | - let divTag = document.createElement('div'); |
| 99 | + const divTag = document.createElement('div'); |
120 | 100 | divTag.className = 'myBooks'; |
121 | 101 |
|
122 | | - let ultag = document.createElement('ul'); |
123 | | - ultag.className = 'books'; |
124 | | - |
125 | | - const body = document.body; |
126 | | - body.appendChild(createList(listBooks)); |
127 | | - |
128 | | - function createList(books) { |
129 | | - const listBooks = document.createElement('ul'); |
130 | | - |
131 | | - for (let i = 0; i < books.length; i++) { |
132 | | - const item = document.createElement('li'); |
133 | | - item.id = books[i]; |
134 | | - item.appendChild(createChild('h2', 'Title', information[books[i]].name)); |
135 | | - item.appendChild( |
136 | | - createChild('p', 'Author: By ', createChild('em', information[books[i]].author)) |
137 | | - ); |
138 | | - item.appendChild( |
139 | | - createChild('div', 'Language: By ', createChild('em', information[books[i]].language)) |
140 | | - ); |
141 | | - item.appendChild( |
142 | | - createChild('div', 'Cover Artist: By ', createChild('em', information[books[i]].Artist)) |
143 | | - ); |
144 | | - |
145 | | - listBooks.appendChild(item); |
146 | | - } |
147 | | - return listBooks; |
148 | | - } |
149 | | - |
150 | | - function createChild(type, ...children) { |
151 | | - const node = document.createElement(type); |
152 | | - |
153 | | - for (const child of children) { |
154 | | - if (typeof child === 'string') { |
155 | | - node.appendChild(document.createTextNode(child)); |
156 | | - } else { |
157 | | - node.appendChild(child); |
158 | | - } |
159 | | - } |
160 | | - |
161 | | - return node; |
162 | | - } |
163 | | - |
164 | | - function capitalizeFirstLetter(string) { |
165 | | - return string.charAt(0).toUpperCase() + string.slice(1); |
166 | | - } |
| 102 | + const ulTag = document.createElement('ul'); |
| 103 | + ulTag.className = 'books'; |
| 104 | + listBooks.forEach(function(id) { |
| 105 | + const img = document.createElement('img'); |
| 106 | + img.src = image[id]; |
| 107 | + img.className = 'cover'; |
| 108 | + const title = document.createElement('h2'); |
| 109 | + title.innerHTML = information[id].name; |
| 110 | + title.className = 'title'; |
| 111 | + const liTag = document.createElement('li'); |
| 112 | + liTag.innerHTML = information[id].author; |
| 113 | + liTag.className = 'book'; |
| 114 | + liTag.appendChild(title); |
| 115 | + liTag.appendChild(img); |
| 116 | + ulTag.appendChild(liTag); |
| 117 | + div.appendChild(divTag); |
| 118 | + divTag.appendChild(ulTag); |
| 119 | + }); |
167 | 120 | } |
168 | 121 |
|
169 | 122 | window.addEventListener('load', main); |
|
0 commit comments