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
30 lines (26 loc) · 937 Bytes
/
app.js
File metadata and controls
30 lines (26 loc) · 937 Bytes
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
"use strict";
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
const GIPHY_URL = "https://api.giphy.com/v1/gifs/translate";
const GIPHY_KEY = "Ey5bj0ls019sN401lqbVmU0aZ1kINfSD";
const searchBtn = document.querySelector("#submitSearch");
const inputSearch = document.querySelector("#searchWord");
const gifImg = document.querySelector("#imageContainer > img");
const feedbackPara = document.querySelector("#feedback");
searchBtn.addEventListener("click", (event) => {
fetch(`${GIPHY_URL}?api_key=${GIPHY_KEY}&s=${inputSearch.value}`)
.then((res) => {
return res.json()
})
.then((body) => {
console.log(body);
gifImg.src = body.data.images.original.url;
inputSearch.value = "";
feedbackPara.textContent = "";
})
.catch((err) => {
feedbackPara.textContent = err.message;
console.log(err);
})
});