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
24 lines (19 loc) · 748 Bytes
/
app.js
File metadata and controls
24 lines (19 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
const searchButton = document.getElementById(`submitSearch`);
const searchInput = document.getElementById(`searchWord`);
const imageElement = document.getElementsByTagName(`img`);
const feedBackPara = document.getElementById(`feedBack`);
searchButton.addEventListener(`click`, getImages);
function getImages() {
fetch(`https://api.giphy.com/v1/gifs/translate?api_key=oiA5a6Z8msUMvCOoZwNxcN5Otb6Pj4vy&s=${searchInput.value}`)
.then((res) => res.json())
.then((giphyObj) => {
imageElement[0].src = giphyObj.data.images.original.url
searchInput.value = ``;
})
.catch((err) => {
feedBackPara.textContent = err.message
});
}