-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (42 loc) · 1.55 KB
/
Copy pathscript.js
File metadata and controls
52 lines (42 loc) · 1.55 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
let publickey = 'public key goes here';
let privatekey = 'private key goes here';
let ts = new Date().getTime();
let hash = CryptoJS.MD5(ts + privatekey + publickey).toString();
let url = "http://gateway.marvel.com/v1/public/characters?name=Iron Man&limit=2"+ '&ts=' + ts + '&apikey=' + publickey + '&hash=' + hash
let heropic = document.querySelector(".heropic")
document.body.style.backgroundColor = "red"
let hero= ["Avengers",
"Spider-Man",
"Hulk",
"Captain America",
"Iron Man",
"Thanos",
"Wolverine",
"Thor",
"Falcon",
"Vision",
"Daredevil"]
let heroBtn = document.querySelector(".heroBtn")
heroBtn.addEventListener("click",marvel)
let counter = 0
marvel()
function marvel(){
url = "http://gateway.marvel.com/v1/public/characters?name="+hero[counter]+"&limit=2"+ '&ts=' + ts + '&apikey=' + publickey + '&hash=' + hash
fetch(url)
.then(res => {
return res.json()
})
.then(res => {
console.log("success!", res)
console.log(res.data.results[0].description)
//let imgPath = res.data.results[0].thumbnail.path + "." + res.data.results[0].thumbnail.extension
let imgPath = res.data.results[0].thumbnail.path + "/" + "portrait_incredible" + "." + res.data.results[0].thumbnail.extension
heropic.setAttribute("src",imgPath)
let about = document.querySelector(".about")
about.innerText = res.data.results[0].description
counter = counter + 1
})
.catch(err => {
console.log("something went wrong.....", err)
})
}