-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (26 loc) · 914 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
// const { displayImages } = require("./helpers.js");
const form = document.querySelector("form");
const imageContainer = document.querySelector("#image-container");
const clearButton = document.querySelector("#clear");
form.addEventListener("submit", async function (e) {
e.preventDefault();
const value = form.elements.query.value;
const config = { params: { q: value } };
const req = await axios.get(`https://api.tvmaze.com/search/shows`, config);
displayImages(req.data);
form.elements.query.value = "";
});
clearButton.addEventListener("click", function () {
imageContainer.innerHTML = "";
});
function displayImages(shows) {
imageContainer.innerHTML = "";
for (let result of shows) {
if (result.show.image) {
const img = document.createElement("IMG");
img.src = result.show.image.medium;
imageContainer.append(img);
}
}
}
module.exports = { displayImages };