This repository was archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathapp.js
More file actions
130 lines (121 loc) · 3.55 KB
/
app.js
File metadata and controls
130 lines (121 loc) · 3.55 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
130
'use strict';
const container = document.querySelector('.main');
const bookTitles = [
'sailor_song',
'lame_fate',
'roadside_picnic',
'a_mind_for_numbers',
'other_shores',
'the_luzhin_defense',
'the_brothers_karamazov',
'one_flew_over_the_cuckoos_nest',
'sharp_objects',
'the_idiot',
];
const bookInfo = {
sailor_song: {
title: 'Sailor song',
language: 'english',
author: 'Ken Kesey',
},
lame_fate: {
title: 'Lame fate',
language: 'russian',
author: 'Arkady Strugatsky and Boris Strugatsky',
},
roadside_picnic: {
title: 'Roadside picnic',
language: 'russian',
author: 'Arkady Strugatsky and Boris Strugatsky',
},
a_mind_for_numbers: {
title: 'A mind for numbers',
language: 'english',
author: 'Barbara Oakley',
},
other_shores: {
title: 'Other Shores',
language: 'russian',
author: 'Vladimir Nabokov',
},
the_luzhin_defense: {
title: 'The Luzhin defense',
language: 'russian',
author: 'Vladimir Nabokov',
},
the_brothers_karamazov: {
title: 'The brothers Karamazov',
language: 'russian',
author: 'Fyodor Dostoyevsky',
},
one_flew_over_the_cuckoos_nest: {
title: "One flew over the cuckoo's nest",
language: 'english',
author: 'Ken Kesey',
},
sharp_objects: {
title: 'Sharp objects',
language: 'english',
author: 'Gillian Flynn',
},
the_idiot: {
title: 'The idiot',
language: 'russian',
author: 'Fyodor Dostoyevsky',
},
};
const bookCovers = {
sailor_song: './images/sailor_song.jpg',
lame_fate: './images/lame_fate.jpg',
roadside_picnic: './images/roadside_picnic.jpg',
a_mind_for_numbers: './images/a_mind_for_numbers.jpg',
other_shores: './images/other_shores.jpg',
the_luzhin_defense: './images/the_luzhin_defense.jpg',
the_brothers_karamazov: './images/the_brothers_karamazov.jpg',
one_flew_over_the_cuckoos_nest: './images/one_flew_over_the_cuckoo_nest.jpg',
sharp_objects: './images/sharp_objects.jpg',
the_idiot: './images/the_idiot.jpg',
};
const ul = document.createElement('ul');
container.append(ul);
function makeBookList(arr, obj) {
for (let i = 0; i < arr.length; i++) {
const li = document.createElement('li');
ul.append(li);
li.setAttribute('id', arr[i]);
const bookContainer = document.createElement('div');
bookContainer.classList.add('book_container');
li.append(bookContainer);
for (const key in obj) {
if (key === arr[i]) {
const title = document.createElement('h1');
title.classList.add('title', `title_${key}`);
const author = document.createElement('h2');
author.classList.add('book_author');
const language = document.createElement('p');
language.classList.add('book_language');
title.textContent = obj[key].title;
author.textContent = obj[key].author;
language.textContent = obj[key].language;
bookContainer.append(title, author, language);
}
}
}
}
makeBookList(bookTitles, bookInfo);
function putBookCovers(bookCoversObj) {
for (const key in bookCoversObj) {
if (typeof bookCoversObj === 'object') {
const li = document.querySelector(`#${key}`);
const h1 = document.querySelector(`.title_${key}`);
if (key === li.getAttribute('id')) {
const image = document.createElement('img');
image.setAttribute('src', `${bookCoversObj[key]}`);
image.setAttribute('alt', `book cover ${key}`);
image.classList.add('book_image');
h1.insertAdjacentElement('afterend', image);
}
}
}
}
putBookCovers(bookCovers);