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