|
| 1 | +//book list i have read |
1 | 2 | 'use strict'; |
2 | | -{ |
3 | | - const bookTitles = [ |
4 | | - // Replace with your own book titles |
5 | | - 'harry_potter_chamber_secrets' |
| 3 | + let bookTitles = [ |
| 4 | + |
| 5 | + 'allison graham_cart to business relationship', |
| 6 | + 'bill vincent_apostolic breakthrough', |
| 7 | + 'jason kro_web development', |
| 8 | + 'shama hoque_full stack react project', |
| 9 | + 'cody lindley_front end handbook', |
| 10 | + 'adam smith_wealth of nations', |
| 11 | + 'hunry potter_chamber of secretes', |
| 12 | + 'karl marx_capital', |
| 13 | + 'vipul sonpatki_react by example', |
| 14 | + 'adam smith_moral sentiments', |
| 15 | + |
6 | 16 | ]; |
7 | 17 |
|
| 18 | + // |
| 19 | + // books changed from JSON to multiple ARRAY. |
| 20 | + // be careful unique keyword=>"bookInfo" in JSON data format.. |
| 21 | +'use strict'; |
| 22 | + let books = [ |
| 23 | + {bookInfo :{ |
| 24 | + title: 'cart to business relationship', |
| 25 | + author : 'allison graham', |
| 26 | + language : 'english', |
| 27 | + }}, |
| 28 | + {bookInfo :{ |
| 29 | + title: 'apostolic breakthrough', |
| 30 | + author : 'bill vincent', |
| 31 | + language : 'english', |
| 32 | + }}, |
| 33 | + {bookInfo :{ |
| 34 | + title: 'web development', |
| 35 | + author : 'jason kro', |
| 36 | + language : 'english', |
| 37 | + }}, |
| 38 | + {bookInfo :{ |
| 39 | + title: 'full stack react project', |
| 40 | + author : 'shama hoque', |
| 41 | + language : 'english', |
| 42 | + }}, |
| 43 | + {bookInfo :{ |
| 44 | + title: 'front end handbook', |
| 45 | + author : 'cody lindley', |
| 46 | + language : 'english', |
| 47 | + }}, |
| 48 | + {bookInfo :{ |
| 49 | + title: 'wealth of nations', |
| 50 | + author : 'adam smith', |
| 51 | + language : 'english', |
| 52 | + }}, |
| 53 | + {bookInfo :{ |
| 54 | + title: 'chamber of secretes', |
| 55 | + author : 'hunry potter', |
| 56 | + language : 'english', |
| 57 | + }}, |
| 58 | + {bookInfo :{ |
| 59 | + title: 'capital', |
| 60 | + author : 'karl marx', |
| 61 | + language : 'english', |
| 62 | + }}, |
| 63 | + {bookInfo :{ |
| 64 | + title: 'react by example', |
| 65 | + author : 'vipul sonpatki', |
| 66 | + language : 'english', |
| 67 | + }}, |
| 68 | + {bookInfo :{ |
| 69 | + title: 'moral sentiments', |
| 70 | + author : 'adam smith', |
| 71 | + language : 'english', |
| 72 | + }} |
| 73 | + ] |
| 74 | + |
| 75 | +// adding "itemClick" event |
| 76 | +let temp = []; |
| 77 | +let itemClick = (e) => { |
| 78 | + let id = e.target.id; |
| 79 | + if(temp.indexOf(id) == -1){ |
| 80 | + temp.push(id); |
| 81 | + |
| 82 | + let title = books[id]['bookInfo']['title']; |
| 83 | + let author = books[id]['bookInfo']['author']; |
| 84 | + let language = books[id]['bookInfo']['language']; |
8 | 85 |
|
9 | | - // Replace with your own code |
10 | | - console.log(bookTitles); |
| 86 | + let str = '<div class="card" onclick="myFunction()">'; |
| 87 | + str += '<p>' + title + '</p>'; |
| 88 | + str += '<img src="./pictures/'+title+'.jpg">'; |
| 89 | + str += '<p> author: ' + author + '</p>'; |
| 90 | + str += '<p> language: ' + language + '</p></div>'; |
| 91 | + document.getElementById('pagecontent').innerHTML += str; |
| 92 | + } |
11 | 93 | } |
| 94 | +// getting list book's id |
| 95 | +bookTitles.forEach(function (bookTitle, i) { |
| 96 | + |
| 97 | + let li = document.createElement('p'); |
| 98 | + li.setAttribute('id', i); |
| 99 | + li.classList.add('book'); |
| 100 | + li.innerHTML = bookTitle; |
| 101 | + li.addEventListener('click', itemClick); |
| 102 | + |
| 103 | + document.getElementById('bookcontainer').appendChild(li); |
| 104 | + |
| 105 | + }); |
| 106 | +// obj with nested props |
| 107 | +function myFunction() { |
| 108 | + document.getElementById('bookcontainer').height="400" |
| 109 | + |
| 110 | +} |
| 111 | + |
| 112 | + |
| 113 | + |
0 commit comments