-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
87 lines (54 loc) · 2.43 KB
/
script.js
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
// fetching data from marvel api
var url = 'https://gateway.marvel.com/v1/public/characters?ts=1&apikey=f8b7f3be1da87fe350873705c6a19730&hash=0bcde198dddfb73187db42904e7c9411';
var titlee = document.createElement('h1');
titlee.classList.add('page-heading');
let attachment = document.querySelector('body');
attachment.insertAdjacentElement('afterbegin', titlee)
let head = document.getElementsByClassName('page-heading')[0];
var marvell = document.createElement('span');
marvell.classList.add('head1');
marvell.innerText = 'MARVEL';
head.append(marvell);
var character = document.createElement('span');
character.classList.add('head2');
character.innerText = 'CHARACTERS';
head.append(character);
let divison = document.createElement('div');
divison.classList.add('container');
divison.classList.add('my-5');
head.insertAdjacentElement('afterend', divison)
let div = document.getElementsByClassName('container')[0];
let divison2 = document.createElement('div');
divison2.classList.add('row');
div.insertAdjacentElement('afterbegin', divison2);
async function marvel() {
try {
let promise = fetch(url);
let response = await promise;
let promise2 = response.json();
let object = await promise2;
let itterate = object.data.results;
cardDetails = ''; // where card details to be attached
for (let i of itterate) { // itterating through the array of objects
cardDetails += `
<div class="col mb-3">
<div class="card h-100">
<div class="card-header bg-dark text-center">
<h1 class="heading">${i.name}</h1>
</div>
<div class="card-body text-center">
<img src=${i.thumbnail.path}/standard_fantastic.${i.thumbnail.extension} alt=image of ${i.name}>
</div>
<div class="card-footer">
<p class="text-muted">for ${i.name}'s comics and series </p>
<a class='btn btn-danger' href=${i.urls[2]?.url} target=_blank>Click Here</a>
</div>
</div>
</div>
`}
document.getElementsByClassName('row')[0].innerHTML = cardDetails; // sorted out the data from api and inserted the data into card through innerHTML
} catch (error) {
console.log(error);
}
}
marvel();