forked from benrbryant/JavaScript_APIs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (43 loc) · 1.26 KB
/
app.js
File metadata and controls
51 lines (43 loc) · 1.26 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
"use strict";
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
let searchBtn = document.getElementById("submitSearch");
let searchInput = document.getElementById("searchWord");
let img = document.querySelector("img");
let feedback = document.querySelector("p");
// Exercise 2 & 3 Section
console.log("EXERCISE 2/3:\n==========\n");
const API_Key = "uTKUl3qvX7eArVjvzWAjgKXGbnf66Iyy";
searchBtn.addEventListener("click", fetchGIF);
/*
function fetchGIF() {
fetch(
`https://api.giphy.com/v1/gifs/translate?api_key=${API_Key}&s=${searchInput}`,
{
mode: "cors",
}
)
.then((res) => res.json())
.then((data) => console.log(data));
}
*/
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
function fetchGIF() {
fetch(
`https://api.giphy.com/v1/gifs/translate?api_key=${API_Key}&s=${searchInput.value}`,
{
mode: "cors",
}
)
.then((res) => res.json())
.then(function (res) {
console.log(searchInput.value);
img.setAttribute("src", res.data.images.original.url);
searchInput.value = "";
feedback =
"Open the Browser Console to view your work (Right-Click => Inspect or fn+F12)";
})
.catch((err) => (feedback = err.message));
}