Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add info and image by checking id
  • Loading branch information
nuanprae committed Feb 17, 2021
commit fd668285723ef308cdcaa9aeff121b21db317973
81 changes: 24 additions & 57 deletions Week1/homework/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
const bookTitles = [
'the_capture',
'the_journey',
'the_rescue',
'the_siege',
'the_shattering',
'the_burning',
'the_hatchling',
'the_outcast',
'the_first_collier',
'the_coming_of_hoole',
'the_rescue',
];
const bookCovers = {
the_capture: './img/thecapture.jpg',
Expand Down Expand Up @@ -77,67 +77,34 @@
author: 'Kathryn Lasky',
},
};

// list bookTitle from array called bookTitles
// const listItems = bookTitles => {
// const ul = document.createElement('ul');
// document.body.appendChild(ul);
// for (let i = 0; i < bookTitles.length; i++) {
// const li = document.createElement('li');
// const bookTitle = bookTitles[i];
// li.innerHTML = bookTitle;
// ul.appendChild(li);
// }
// };
// listItems(bookTitles);
const listItems = (ids, bookInfo) => {
const listItems = (ids, info, images) => {
const ul = document.createElement('ul');
document.body.appendChild(ul);
for (let i = 0; i < ids.length; i++) {
const li = document.createElement('li');
const id = ids[i];
const bookInfoKeys = Object.keys(bookInfo);
if (id === bookInfoKeys[i]) {
li.innerHTML = bookInfo[bookInfoKeys[i]].title;
ul.appendChild(li);
}
}
};
listItems(bookTitles, guardiansOfGahooleSeries);
const img = document.createElement('img');
const heading = document.createElement('h1');
const subHeading1 = document.createElement('h2');
const subHeading2 = document.createElement('h2');
li.setAttribute('id', ids[i]);

// const listItems = (img, info) => {
// const ul = document.createElement('ul');
// document.body.appendChild(ul);
// const imgKeys = Object.keys(img);
// const infoKeys = Object.keys(info);
// for (let i = 0; i < infoKeys.length; i++) {
// const li = document.createElement('li');
// const image = document.createElement('img');
// const heading = document.createElement('h1');
// const subHeading1 = document.createElement('h2');
// const subHeading2 = document.createElement('h2');
ul.appendChild(li);
const id = li.getAttribute('id');
const src = images[id];
const title = info[id].title;
const language = info[id].language;
const author = info[id].author;

// // accessing values inside object
// const title = info[infoKeys[i]].title;
// const language = info[infoKeys[i]].language;
// const author = info[infoKeys[i]].author;
// heading.innerHTML = title;
// subHeading1.innerHTML = `Language: ${author}`;
// subHeading2.innerHTML = `Author: ${language}`;
img.src = src;
heading.innerHTML = title;
subHeading1.innerHTML = `Language: ${language}`;
subHeading2.innerHTML = `Author: ${author}`;

// const check = () => {
// if (image) {
// }
// };
// image.src = img[imgKeys[i]];

// ul.appendChild(li);
// li.appendChild(image);
// li.appendChild(heading);
// li.appendChild(subHeading1);
// li.appendChild(subHeading2);
// }
// };

// listItems(bookCovers, guardiansOfGahooleSeries);
li.appendChild(img);
li.appendChild(heading);
li.appendChild(subHeading1);
li.appendChild(subHeading2);
}
};
listItems(bookTitles, guardiansOfGahooleSeries, bookCovers);
}