Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
129 lines (120 loc) · 3.35 KB
/
Copy pathapp.js
File metadata and controls
129 lines (120 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// "use strict";
const bookNames = [
'tanios',
'what_is_to_be_done',
'the_sorrows_of_young_werther',
'red_rocks',
'the_impatient_ones',
'first_love',
'lord_of_the_flies',
'la_dame_aux_camelias',
'oblomov',
'cement',
];
const bookDetails = {
tanios: {
title: 'The Rock of Tanios',
author: 'Amin Maalouf',
language: 'Arabic',
},
what_is_to_be_done: {
title: 'What Is To Be Done?',
author: 'Chernyshevsky',
language: 'Russian',
},
the_sorrows_of_young_werther: {
title: 'The Sorrows of Young Werther',
author: 'Goethe',
language: 'German',
},
red_rocks: {
title: 'Red Rocks',
author: 'Yang Piyen - Luo Kuangpin',
language: 'Chinese',
},
the_impatient_ones: {
title: 'The Impatient Ones',
author: 'Yuri Trifonov',
language: 'Russian',
},
first_love: {
title: 'First Love',
author: 'Turgenyev',
language: 'Russian',
},
lord_of_the_flies: {
title: 'Lord of The Flies',
author: 'Goethe',
language: 'German',
},
la_dame_aux_camelias: {
title: 'Madame Aux Camelias',
author: 'Alexander Dumas',
language: 'French',
},
oblomov: {
title: 'Oblomov',
author: 'Ivan Goncharov',
language: 'Russian',
},
cement: {
title: 'Cement',
author: 'Fyodor Vasilievich Gladkov',
language: 'Russian',
},
};
const bookCovers = {
tanios: 'img/tanios.jpg',
what_is_to_be_done: 'img/what_is_to_be_done.jpg',
the_sorrows_of_young_werther: 'img/the_sorrows_of_young_werther.jpg',
red_rocks: 'img/red_rocks.jpg',
the_impatient_ones: 'img/the_impatient_ones.jpg',
first_love: 'img/first_love.jpg',
lord_of_the_flies: 'img/lord_of_the_flies.jpg',
la_dame_aux_camelias: 'img/la_dame_aux_camelias.jpg',
oblomov: 'img/oblomov.jpg',
cement: 'img/cement.jpg',
};
const mainDiv = document.getElementById('mainDiv');
const h1 = document.createElement('h1');
h1.textContent = 'My Favorite Books';
mainDiv.appendChild(h1);
const ulist = document.createElement('ul');
mainDiv.appendChild(ulist);
function uploadingBooks() {
for (let details in bookDetails) {
const bookTitles = document.createElement('li');
ulist.appendChild(bookTitles);
const bookAuthors = document.createElement('a');
ulist.appendChild(bookAuthors);
const titles = bookDetails[details].title;
const bookLanguage = document.createElement('a');
ulist.appendChild(bookLanguage);
bookTitles.textContent = titles;
const authors = bookDetails[details].author;
bookAuthors.textContent = 'Author: ' + authors;
const language = bookDetails[details].language;
bookLanguage.textContent = language;
}
}
const idTagsForBookNames = () => {
const titleList = document.querySelectorAll('li');
for (let i = 0; i < bookNames.length; i++) {
titleList[i].setAttribute('id', bookNames[i]);
}
};
const placingImagesToListItems = () => {
for (let img in bookCovers) {
const image = document.createElement('img');
image.setAttribute('class', 'images');
image.setAttribute('src', bookCovers[img]);
image.setAttribute('alt', img);
document.getElementById(img).appendChild(image);
}
};
const main = () => {
uploadingBooks();
idTagsForBookNames();
placingImagesToListItems();
};
window.onload = () => main();