-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.js
68 lines (62 loc) · 3.25 KB
/
hero.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
var PrsnlDtls=document.getElementById('personalDetail');
var Biography=document.getElementById('biography');
var powerstats=document.getElementById('powerstats');
var imageSuper = document.getElementById("imageSuper");
function retrive(ShId) {
fetch('https://www.superheroapi.com/api.php/1358348604650444/'+ShId)
.then(function (e) {
return e.json();
})
.then(function (data) {
console.log("data", data);
// console.log(data.image.url);
PrintResults(data);
return data;
})
}
// on load run
window.onload = function(){
let winurl = window.location.href;
console.log(winurl);
let ShId = winurl.substring(winurl.lastIndexOf('=') + 1);
console.log(ShId);
retrive(ShId);
}
// print deatils of biograph,powerstar,main image
function PrintResults(data) {
console.log(data.image.url);
imageSuper.src = data.image.url;
ul1 = document.createElement('ul');
ul1.innerHTML = `
<h1>${data.name}</h1>
<p><strong>Gender : </strong>${data.appearance.gender}</p>
<p><strong>Race : </strong>${data["appearance"]["race"]}</p>
<p><strong>Hair-Color : </strong>${data['appearance']['hair-color']}</p>
<p><strong>Height : </strong>${data.appearance.height}</p>
<p><strong>Eye-Color : </strong>${data["appearance"]["eye-color"]}</p>
<p><strong>Weight : </strong>${data.appearance.weight}</p>
`
PrsnlDtls.appendChild(ul1);
ul2 = document.createElement('ul');
ul2.innerHTML = `
<p><strong>Aliases : </strong>[${data["biography"]["aliases"].slice(0,10)}]</p>
<p><strong>Alignment : </strong>${data.biography.alignment}</p>
<p><strong>Alter-Egos : </strong>${data["biography"]["alter-egos"]}</p>
<p><strong>First-Appearance : </strong>${data["biography"]["first-appearance"].slice(0,10)}</p>
<p><strong>Full-Name : </strong>${data["biography"]["full-name"]}</p>
<p><strong>Place-Of-Birth: </strong>${data["biography"]["place-of-birth"]}</p>
<p><strong>Publisher: </strong>${data["biography"]["publisher"]}</p>
`
Biography.appendChild(ul2);
ul3 = document.createElement('ul');
ul3.innerHTML = `
<p><strong>Combat :   </strong>${data.powerstats.combat}</p>
<p><strong>Durability :  </strong>${data.powerstats.durability}</p>
<p><strong>Intelligence :  </strong>${data["powerstats"]["intelligence"]}</p>
<p><strong>Power :    </strong>${data["powerstats"]["power"]}</p>
<p><strong>Speed :    </strong>${data["powerstats"]["speed"]}</p>
<p><strong>Strength:   </strong>${data["powerstats"]["strength"]}</p>
<p><strong>Strength:  </strong>${data["work"]["occupation"]}</p>
`
powerstats.appendChild(ul3);
}