-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (29 loc) · 992 Bytes
/
app.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
const img = document.querySelector("img");
const button = document.getElementById("button");
const searchButton = document.getElementById("searchbutton");
const searchField = document.getElementById("searchfield");
let defaultURL =
"https://api.giphy.com/v1/gifs/translate?api_key=WRfYXYKJrVZpZ8ARkoeTRdNrYJ3E96Q0&s=";
async function getCats() {
const response = await fetch(
"https://api.giphy.com/v1/gifs/translate?api_key=WRfYXYKJrVZpZ8ARkoeTRdNrYJ3E96Q0&s=cats",
{ mode: "cors" }
);
const catData = await response.json();
img.src = catData.data.images.original.url;
}
async function getSearch() {
const response = await fetch(defaultURL.concat(searchField.value), {
mode: "cors",
});
const searchData = await response.json();
img.src = searchData.data.images.original.url;
}
searchButton.addEventListener("click", function () {
if (searchField.value != "") {
getSearch();
}
});
button.addEventListener("click", function () {
getCats();
});