forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathapp.js
More file actions
186 lines (167 loc) · 5.42 KB
/
app.js
File metadata and controls
186 lines (167 loc) · 5.42 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// 'use strict';
// const bookTitles = [
// 'memoirs_of_a_geisha',
// 'enma_the_immortal',
// 'confessions',
// 'coin_locker_babies',
// 'beauty_and_sadness',
// 'house_of_sleeping_beauties',
// 'empress',
// 'the_next_continent',
// 'underground',
// 'after_dark',
// ];
let booksInfo = {
memoirs_of_a_geisha: {
properties: {
title: 'Memoirs of a Geisha',
language: 'English',
author: 'Arthur Golden',
},
},
enma_the_immortal: {
properties: {
title: 'Enma the Immortal',
language: 'Japanese',
author: 'Fumi Nakamura',
},
},
confessions: {
properties: {
title: 'Confessions',
language: 'Japanese',
author: 'Kanae Minato',
},
},
coin_locker_babies: {
properties: {
title: 'Coin Locker Babies',
language: 'Japanese',
author: 'Ryu Murakami',
},
},
beauty_and_sadness: {
properties: {
title: 'Beauty and Sadness',
language: 'Japanese',
author: 'Yasunari Kawabata',
},
},
house_of_sleeping_beauties: {
properties: {
title: 'House of Sleeping Beauties',
language: 'Japanese',
author: 'Yasunari Kawabata',
},
},
empress: {
properties: {
title: 'Empress',
language: 'English',
author: 'Shan Sa',
},
},
the_next_continent: {
properties: {
title: 'The Next Continent',
language: 'English',
author: 'Issui Ogawa',
},
},
underground: {
properties: {
title: 'Underground',
language: 'Japanese',
author: 'Haruki Murakami',
},
},
after_dark: {
properties: {
title: 'After Dark',
language: 'Japanese',
author: 'Haruki Murakami',
},
},
};
// 1.3
// window.onload = () => {
// const myBookList = ['Book1', 'Book2', 'Book3', 'Book4', 'Book5', 'Book6'];
// const myBookSpot = document.querySelector('#bookList');
// const ol = document.createElement('ol');
// for (const book of myBookList) {
// const li = document.createElement('li');
// li.appendChild(document.createTextNode(book));
// ol.appendChild(li);
// }
// myBookSpot.appendChild(ol);
// };
window.onload = () => {
const quotes = [
'If you only read the books that everyone else is reading, you can only think what everyone else is thinking. ― Haruki Murakami',
'Memories warm you up from the inside. But they also tear you apart. ― Haruki Murakami',
"If you remember me, then I don't care if everyone else forgets. ― Haruki Murakami",
"There's no such thing as perfect writing, just like there's no such thing as perfect despair. - Haruki Murakami",
'They were words that came out of nothing, but they seemed to him somehow significant.He muttered them over again. - Yasunari Kawabata',
'Remember the good things; write the bad ones down in here and forget about them.― Kanae Minato',
"Just because I've written this book, don't think I've changed. I'm like I was back then, really. - Ryu Murakami",
];
console.log(quotes);
const rand = quotes[Math.floor(Math.random() * quotes.length)];
const quoteSpace = document.querySelector('#quoteSpace');
const quoteDiv = document.createElement('div');
quoteDiv.innerText = rand;
quoteSpace.appendChild(quoteDiv);
const myBookSpot = document.querySelector('#bookList');
const div = document.createElement('div');
div.setAttribute('class', 'wrapper');
// eslint-disable-next-line guard-for-in
for (book in booksInfo) {
const eachBookDiv = document.createElement('div');
eachBookDiv.id = book;
eachBookDiv.setAttribute('class', 'box');
const name = document.createElement('h4');
name.innerText = booksInfo[book].properties.title;
eachBookDiv.appendChild(name);
const ul = document.createElement('ul');
const author = document.createElement('li');
author.innerText = booksInfo[book].properties.author;
ul.appendChild(author);
const language = document.createElement('li');
language.innerText = booksInfo[book].properties.language;
ul.appendChild(language);
eachBookDiv.appendChild(ul);
div.appendChild(eachBookDiv);
myBookSpot.appendChild(div);
}
console.log('loaded');
const bookImages = [
{ memoirs_of_a_geisha: 'book_covers/memoirs_of_a_geisha_img.jpg' },
{ enma_the_immortal: 'book_covers/enma_the_immortal_img.jpg' },
{ confessions: 'book_covers/confessions_img.jpg' },
{ coin_locker_babies: 'book_covers/coin_locker_babies_img.jpg' },
{ beauty_and_sadness: 'book_covers/beauty_and_sadness_img.jpg' },
{ house_of_sleeping_beauties: 'book_covers/house_of_sleeping_beauties_img.jpg' },
{ empress: 'book_covers/empress_img.jpg' },
{ the_next_continent: 'book_covers/the_next_continent_img.jpg' },
{ underground: 'book_covers/underground_img.jpg' },
{ after_dark: 'book_covers/after_dark_img.jpg' },
];
// function addBookImages(bookPics) {
// const length = bookPics.length;
// for (let i = 0; i < length; i++) {
// console.log(i);
// // document.querySelector(bookPics.pic)
// }
// }
// addBookImages(bookImages);
// console.log(bookImages);
// eslint-disable-next-line guard-for-in
for (image in bookImages) {
const imageID = Object.keys(bookImages[image])[0];
const lookFor = document.querySelector(`#${imageID}`);
const picture = document.createElement('IMG');
picture.src = bookImages[image][imageID];
lookFor.appendChild(picture);
console.log(imageID, lookFor);
}
};