-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (27 loc) · 873 Bytes
/
Copy pathscript.js
File metadata and controls
42 lines (27 loc) · 873 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const searchInput = document.querySelector('#searchInput');;
const btn = document.querySelector('#btn');
const result = document.querySelector('.result');
const apiKey = '247dafca';
async function getData(movie){
const response = await fetch(`https://www.omdbapi.com/?apikey=${apiKey}&s=${movie}`);
if(!response.ok){
throw new Error ('Something went wrong')
}
const movien = await response.json();
console.log(movien);
displayData(movien);
}
btn.addEventListener('click', () => {
const movie = searchInput.value;
if (movie) {
getData(movie);
}
});
const displayData=(data)=>{
data.Search.forEach((movie)=>{
const html =` <p> movie title: ${movie.Title} </p>
<p> movie year: ${movie.Year} </p>
<p> movie type: ${movie.Type} </p>`
result.innerHTML+=html;
})
}