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
129 lines (110 loc) · 3.07 KB
/
app.js
File metadata and controls
129 lines (110 loc) · 3.07 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';
document.body.style.backgroundColor = '#40E0D0';
// array of books containing 10 strings. lowercase
const bookNames = [
'going_down_river_road',
'the_river_and_the_source',
"salem's_lot",
'americanah',
'things_fall_apart',
'animal_farm',
'the_river_between',
'the_dead_stay_dumb',
'arrow_of_god',
'a_song_of_ice_and_fire',
];
const showBooks = Object.values(bookNames);
console.log(showBooks);
// the part below not showing on console on chrome
// function printBookNames(bookNames) {
// console.table(bookNames);
// }
//printing out the string of the above array:
for (let i = 0; i < bookNames.length; i++) {
console.log(bookNames[i]);
}
const header = document.querySelector('header');
const h1 = header.querySelector('h1'); //getting h1 elem inside of header
h1.textContent = 'Loading Book Recommendations ..';
const p1 = header.querySelector('p');
p1.id = 'p1';
p1.innerHTML = '<i>Some of the books I have read over the past years include the following</i>';
// eslint-disable-next-line no-unused-vars
// 1.3. Make a function (or functions) that generate a ul with li elements for each book ID in the array using a for loop.
// 1.4 create object containing details of each book:
const bookDetails = {
going_down_river_road: {
title: 'Going Down River Road',
author: 'Meja Mwangi',
language: 'English',
published: 1976,
},
the_river_and_the_source: {
title: 'The River And The Source',
author: 'Margaret Ogola',
language: 'English',
published: 1994,
},
homing_in: {
title: 'Salem´s Lot',
author: 'Stephen King',
language: 'English',
published: 1975,
},
americanah: {
title: 'Americanah',
author: 'Chimamanda Ngozi Adichie',
language: 'English',
published: 2013,
},
things_fall_apart: {
title: 'Things Fall Apart',
author: 'Chinua Achebe',
language: 'English',
published: 1958,
},
animal_farm: {
title: 'Animal Farm',
author: 'George Orwell',
language: 'English',
published: 1945,
},
the_river_between: {
title: 'The River Between',
author: 'Ngugi wa Thiong´o',
language: 'English',
published: 1965,
},
the_dead_stay_dumb: {
title: 'The Dead Stay Dumb',
author: 'James Hardley Chase',
language: 'English',
published: 1939,
},
fictitious_book: {
title: 'Arrow of God',
author: 'Chinua Achebe',
language: 'English',
published: 1964,
},
and_another_one: {
title: 'A Song of Ice and Fire',
author: 'George R.R. Martin',
language: 'English',
published: 1996,
},
};
console.log(Object.keys(bookDetails));
const createBookList = document.createElement('ul');
for (let key in bookDetails) {
let li = document.createElement('li');
li.id = 'book';
//let = document.createElement('p');
li.innerText = bookDetails[key].title;
li.innerText = bookDetails[key].author;
li.innerText = bookDetails[key].language;
li.innerText = bookDetails[key].published;
createBookList.appendChild(li);
document.getElementById('book-list').appendChild(createBookList);
}
console.log(createBookList);