|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +document.addEventListener('DOMContentLoaded', function() { |
| 4 | + const bookTitles = [ |
| 5 | + // Replace with your own book titles |
| 6 | + "sophie's_world", |
| 7 | + 'lord_of_the_rings', |
| 8 | + 'of_mice_and_men', |
| 9 | + 'the_brothers_karamazov', |
| 10 | + 'a_farewell_to_the_arms', |
| 11 | + 'lord_of_the_flies', |
| 12 | + 'the_dark_tower', |
| 13 | + 'love_story', |
| 14 | + 'harry_potter_chamber_secrets', |
| 15 | + 'metamorphoses_and_other_stories', |
| 16 | + ]; |
| 17 | + |
| 18 | + const books = { |
| 19 | + harry_potter_chamber_secrets: { |
| 20 | + title: 'Harry Potter Chamber Secrets', |
| 21 | + language: 'English', |
| 22 | + author: 'JK Rowling', |
| 23 | + }, |
| 24 | + "sophie's_world": { title: "Sophie's World", language: 'English', author: 'Josten Gaarder' }, |
| 25 | + metamorphoses_and_other_stories: { |
| 26 | + title: 'Metamorphoses And Other Stories', |
| 27 | + language: 'English', |
| 28 | + author: 'Franz Kafka', |
| 29 | + }, |
| 30 | + lord_of_the_rings: { title: 'Lord Of The Rings', language: 'English', author: 'JJ Tolkien' }, |
| 31 | + of_mice_and_men: { title: 'Of Mice And Men', language: 'English', author: 'John Steinbeck' }, |
| 32 | + the_brothers_karamazov: { |
| 33 | + title: 'The Brothers Karamazov', |
| 34 | + language: 'English', |
| 35 | + author: 'Fyodor Dostoevsky', |
| 36 | + }, |
| 37 | + a_farewell_to_the_arms: { |
| 38 | + title: 'A Farewell To The Arms', |
| 39 | + language: 'English', |
| 40 | + author: 'Ernst Hemmingway', |
| 41 | + }, |
| 42 | + lord_of_the_flies: { |
| 43 | + title: 'Lord Of The Flies', |
| 44 | + language: 'English', |
| 45 | + author: 'William Golding', |
| 46 | + }, |
| 47 | + the_dark_tower: { title: 'The Dark Tower', language: 'English', author: 'Stephen King' }, |
| 48 | + love_story: { title: 'Love Story', language: 'English', author: 'Erich Segal' }, |
| 49 | + }; |
| 50 | + |
| 51 | + const imgSrc = { |
| 52 | + harry_potter_chamber_secrets: './images/harry_potter_chamber_secrets.jpg', |
| 53 | + "sophie's_world": "./images/sophie's_world.jpg", |
| 54 | + metamorphoses_and_other_stories: './images/metamorphoses_and_other_stories.jpg', |
| 55 | + lord_of_the_rings: './images/lord_of_the_rings.jpg', |
| 56 | + of_mice_and_men: './images/of_mice_and_men.jpg', |
| 57 | + the_brothers_karamazov: './images/the_brothers_karamazov.jpg', |
| 58 | + a_farewell_to_the_arms: './images/a_farewell_to_the_arms.jpg', |
| 59 | + lord_of_the_flies: './images/lord_of_the_flies.jpg', |
| 60 | + the_dark_tower: './images/the_dark_tower.jpg', |
| 61 | + love_story: './images/love_story.jpg', |
| 62 | + }; |
| 63 | + |
| 64 | + function addLi(ul) { |
| 65 | + for (let i = 0; i < bookTitles.length; i++) { |
| 66 | + const li = document.createElement('li'); |
| 67 | + const title = document.createElement('h3'); |
| 68 | + const author = document.createElement('h4'); |
| 69 | + const language = document.createElement('h4'); |
| 70 | + ul.appendChild(li); |
| 71 | + li.appendChild(title); |
| 72 | + li.appendChild(author); |
| 73 | + li.appendChild(language); |
| 74 | + li.setAttribute('id', bookTitles[i]); |
| 75 | + title.innerText = books[bookTitles[i]].title; |
| 76 | + author.innerText = books[bookTitles[i]].author; |
| 77 | + language.innerText = books[bookTitles[i]].language; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + function addImg() { |
| 82 | + for (let i = 0; i < bookTitles.length; i++) { |
| 83 | + const li = document.getElementById(bookTitles[i]); |
| 84 | + const img = document.createElement('img'); |
| 85 | + li.appendChild(img); |
| 86 | + img.src = imgSrc[li.id]; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + function main() { |
| 91 | + const div = document.createElement('div'); |
| 92 | + const ul = document.createElement('ul'); |
| 93 | + document.body.appendChild(div); |
| 94 | + div.appendChild(ul); |
| 95 | + addLi(ul); |
| 96 | + addImg(); |
| 97 | + } |
| 98 | + |
| 99 | + window.addEventListener('load', main); |
| 100 | +}); |
0 commit comments