-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (37 loc) · 1.13 KB
/
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
38
39
40
41
42
const form = document.querySelector('form');
const container = document.querySelector('#container');
const link = 'https://api.tvmaze.com/search/shows?q='
const errorline = () => {
const h1 = document.createElement('h1')
h1.innerHTML = 'Sorry! 😔 No movies found....'
h1.style.fontWeight = '400'
container.append(h1)
}
const displayimage = (results) => {
if (results.length == 0)
errorline();
else {
for (let result of results) {
if (result.show.image != null) {
const img = document.createElement('img');
img.src = result.show.image.medium;
img.style.margin = '10px'
container.append(img);
}
}
}
}
form.addEventListener('submit', async (e) => {
e.preventDefault();
container.innerHTML = ''
const query = form.elements.search.value;
const config = { params: { q: query } }
try {
const res = await axios.get(`https://api.tvmaze.com/search/shows`, config)
displayimage(res.data)
}
catch (e) {
errorline();
}
form.elements.search.value = ''
});