-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
56 lines (40 loc) · 1.46 KB
/
scripts.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
console.log("Hello World!");
var imageObject;
var imageURL;
var fetchedData;
console.log("After declaring the 3 variables");
function fetchRandomImage () {
let randomNum = Math.floor(Math.random() * 101);
async function fetchImage() {
var tempImageURL;
let junk = await fetch('https://api.imgflip.com/get_memes')
.then(response => {
//handle response
fetchedData = response.json();
console.log(fetchedData);
fetchedData.then((data) => {
console.log(data);
console.log("Image:");
console.log(data["data"]["memes"]["0"]);
imageObject = data["data"]["memes"]["0"]; // problem cannot assign global imageObject or imageURl
console.log(imageObject);
console.log(data["data"]["memes"]["0"]["url"]);
imageURL = data["data"]["memes"]["0"]["url"];
tempImageURL = data["data"]["memes"][randomNum.toString()]["url"];
console.log(imageURL);
console.log(tempImageURL);
document.getElementById("meme").style.display = "inline";
document.getElementById("meme").src = tempImageURL;
});
});
//imageURL = tempImageURL;
console.log(tempImageURL);
}
fetchImage();
};
console.log("After calling fetchImage function");
console.log("after fetchImage function");
document.getElementById("getMemeBtn").onclick = fetchRandomImage;
//console.log(imageObject);
//console.log(imageURL);
//console.log(fetchedData);