-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (52 loc) · 2.18 KB
/
script.js
File metadata and controls
66 lines (52 loc) · 2.18 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
// Implement the Ice and Fire API using async/await with fetch.
let page = 1;
const booksPerPage = 50;
const ApiUrl = `https://anapioficeandfire.com/api/books?page=${page}&pageSize=${booksPerPage}`
async function fetchBooks(){
try{
const response = await fetch(ApiUrl);
const booksdata = await response.json();
// const booksdata = data.slice(0, 50);
// console.log(booksdata);
const resultContainer = document.getElementById('result');
resultContainer.innerHTML = '';
for(let book of booksdata){
const bookContainer = document.createElement('div');
const name = document.createElement('h2');
name.textContent = book.name;
bookContainer.appendChild(name);
const isbn = document.createElement('p');
isbn.textContent = `ISBN: ${book.isbn}`;
bookContainer.appendChild(isbn);
const pages = document.createElement('p');
pages.textContent = `NumberOfPages: ${book.numberOfPages}`;
bookContainer.appendChild(pages);
const author = document.createElement('p');
author.textContent = `Author: ${book.author}`;
bookContainer.appendChild(author);
const publisher = document.createElement('p');
publisher.textContent = `Publisher: ${book.publisher}`;
bookContainer.appendChild(publisher);
const released = document.createElement('p');
released.textContent = `Released: ${book.released}`;
bookContainer.appendChild(released);
const characters = document.createElement('p');
characters.textContent = `Characters: ${book.characters}`;
bookContainer.appendChild(characters);
resultContainer.appendChild(bookContainer);
}
}catch{
console.log("somthing error");
}
}
document.getElementById('previous').addEventListener('click', ()=>{
if(page > 1){
page--;
fetchBooks();
}
});
document.getElementById('next').addEventListener('click', ()=>{
page++;
fetchBooks();
});
fetchBooks()