Skip to content

Commit 491b365

Browse files
committed
added images and finished the assignment
Created an image folder and created a simple bookshelf design with the books that I have read.
1 parent 768acf2 commit 491b365

13 files changed

Lines changed: 187 additions & 7 deletions

‎Week1/homework/app.js‎

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,129 @@
11
'use strict';
22

33
{
4-
const bookTitles = [
5-
// Replace with your own book titles
6-
'harry_potter_chamber_secrets',
7-
];
4+
// const bookTitles = [
5+
// 'harry_potter_chamber_secrets',
6+
// '1984',
7+
// 'before_i_die',
8+
// 'abduction',
9+
// 'divina_comedia',
10+
// 'a_friendly_sloth',
11+
// 'the_pope_and_a_bottle_of_wine',
12+
// 'midnight_stories',
13+
// 'unsung_war_songs',
14+
// 'the_overthinking_lobster',
15+
// ];
816

917
// Replace with your own code
10-
console.log(bookTitles);
18+
const myBooks = {
19+
harry_potter_chamber_secrets: {
20+
title: 'Harry Potter and the Chambers of Secrets',
21+
language: 'english',
22+
author: 'J.K. Rowling',
23+
},
24+
'1984': {
25+
title: '1984',
26+
language: 'english',
27+
author: 'George Orwell',
28+
},
29+
before_i_die: {
30+
title: 'Before I Die',
31+
language: 'english',
32+
author: 'Jenny Downham',
33+
},
34+
abduction: {
35+
title: 'Abduction',
36+
language: 'english',
37+
author: 'Alex Markus',
38+
},
39+
divina_comedia: {
40+
title: 'Divina Comedia',
41+
language: 'english',
42+
author: 'Dante Aligheri',
43+
},
44+
a_friendly_koala: {
45+
title: 'A friendly Koala',
46+
language: 'english',
47+
author: 'Lazy Slothness',
48+
},
49+
the_pope_and_a_bottle_of_wine: {
50+
title: 'The pope and a bottle of wine',
51+
language: 'english',
52+
author: 'Pope Francis',
53+
},
54+
midnight_stories: {
55+
title: 'Midnight Stories',
56+
language: 'english',
57+
author: 'James Arthur',
58+
},
59+
unsung_war_songs: {
60+
title: 'Unsung War Songs',
61+
language: 'english',
62+
author: 'Ginger Axe',
63+
},
64+
the_overthingking_lobster: {
65+
title: 'The Overthinking Lobster',
66+
language: 'english',
67+
author: 'Basic Cheff',
68+
},
69+
};
70+
const bookImages = {
71+
harry_potter_chamber_secrets: './img/chamber_of_secrets_cover.jpg',
72+
'1984': './img/1984_cover.jpg',
73+
before_i_die: './img/before_i_die_cover.jpg',
74+
abduction: './img/abduction_cover.jpg',
75+
divina_comedia: './img/divina_comedia_cover.jpg',
76+
a_friendly_koala: './img/friendly_koala_cover.jpg',
77+
the_pope_and_a_bottle_of_wine: './img/pope_wine_cover.jpg',
78+
midnight_stories: './img/midnight_stories_cover.jpg',
79+
unsung_war_songs: './img/unsung_war_songs_cover.jpg',
80+
the_overthingking_lobster: './img/overthinking_lobster_cover.jpg',
81+
};
82+
console.log(bookImages);
83+
const getBody = document.querySelector('body');
84+
const createShelf = document.createElement('div');
85+
createShelf.setAttribute('class', 'shelf');
86+
getBody.appendChild(createShelf);
87+
88+
function makeBooks() {
89+
for (const el in myBooks) {
90+
if (el !== {}) {
91+
const book = document.createElement('div');
92+
const bookTitle = document.createElement('h2');
93+
const bookAuthor = document.createElement('div');
94+
const bookLanguage = document.createElement('div');
95+
book.setAttribute('class', 'book-item');
96+
book.setAttribute('id', el);
97+
bookTitle.setAttribute('class', 'book-item_title');
98+
bookAuthor.setAttribute('class', 'book-item_author');
99+
bookLanguage.setAttribute('class', 'book-item_language');
100+
bookTitle.innerHTML = myBooks[el].title;
101+
bookAuthor.innerHTML = `by ${myBooks[el].author}`;
102+
bookLanguage.innerHTML = `in ${myBooks[el].language}`;
103+
book.appendChild(bookTitle);
104+
book.appendChild(bookAuthor);
105+
book.appendChild(bookLanguage);
106+
createShelf.appendChild(book);
107+
}
108+
}
109+
}
110+
makeBooks();
111+
112+
const getNrBooks = document.querySelector('.shelf').childElementCount;
113+
const getBooks = document.querySelectorAll('.book-item');
114+
console.log(getBooks);
115+
const arrayImageIds = Object.keys(bookImages);
116+
const arrayImageUrl = Object.values(bookImages);
117+
console.log(arrayImageUrl);
118+
console.log(arrayImageIds);
119+
function addBookImage() {
120+
for (let i = 0; i < getNrBooks; i++) {
121+
if (getBooks[i].id === arrayImageIds[i]) {
122+
getBooks[i].style.backgroundImage = `url(${arrayImageUrl[i]}) `;
123+
} else {
124+
return;
125+
}
126+
}
127+
}
128+
addBookImage();
11129
}

‎Week1/homework/img/1984_cover.jpg‎

3.05 MB
Loading
3.38 MB
Loading
3.02 MB
Loading
635 KB
Loading
473 KB
Loading
997 KB
Loading
1.65 MB
Loading
1.26 MB
Loading
3.05 MB
Loading

0 commit comments

Comments
 (0)