-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (44 loc) · 1.61 KB
/
script.js
File metadata and controls
49 lines (44 loc) · 1.61 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
const accesstoken = '2186461481744946'
const superherourl ="https://superheroapi.com/api.php/"
const searchurl = document.getElementById('SuperHeroSearch')
searchurl.onclick =()=>
{const name=document.getElementById('inputelement').value
searchSuperHero(superherourl,accesstoken,name)}
function searchSuperHero(superherourl,accesstoken,name){
fetch(`${superherourl}/${accesstoken}/search/${name}`)
.then(response => response.json())
.then(json =>
{
const hero =json.results[0].id
superherosearch(hero)
})
}
function superherosearch(ll){
fetch(`${superherourl}/${accesstoken}/${ll}`)
.then(response => response.json())
.then(json =>
{
const image= json.image.url
const name = json.name
const stats = json.powerstats.intelligence
document.getElementById('holderdiv').innerHTML +=`<img src='${image}'>`
document.getElementById('holderdiv').innerHTML += `<p> name:${name} <br> powerstats => intelligance :${stats}<br>
publisher:${json.biography.publisher}</p>`
})
}
const random = document.getElementById('RandomSuperHero')
function randomsuperhero(){
const random = Math.floor((Math.random()*731 )+1)
fetch(`${superherourl}/${accesstoken}/${random}`)
.then(response => response.json())
.then(json =>
{
const image= json.image.url
const name = json.name
const stats = json.powerstats.intelligence
document.getElementById('holderdiv').innerHTML +=`<img src='${image}'>`
document.getElementById('holderdiv').innerHTML += `<p> name:${name} <br> powerstats => intelligance :${stats}<br>
publisher:${json.biography.publisher}</p>`
})
}
random.onclick=()=>randomsuperhero()