-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie-search-engine.js
59 lines (41 loc) · 1.95 KB
/
movie-search-engine.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let dataDiv = document.getElementById("dataDiv");
let errorGif = document.getElementById('error-msg');
//Fetching the data from the app
async function movieData() {
try {
let movieName = document.querySelector('.movie-name').value;
let response = await fetch(`https://www.omdbapi.com/?s=${movieName}&i&apikey=4ec9d444`);
let result = await response.json();
// console.log('result:', result)
let movieResults = result.Search;
display(movieResults)
}
catch (error) {
// console.log('error:', error);
alert('Movie is not available');
errorGif.style.display = 'block';
setTimeout(() => {
location.reload();
},4000)
}
}
//display the movies
function display(movieResults) {
dataDiv.innerHTML = '';
movieResults.forEach(function(data){
console.log('data:', data)
console.log('movieResultsinn:', movieResults)
const moviePoster = document.createElement('img');
const movieName = document.createElement('p');
const movieYear = document.createElement('p');
const movieRatings = document.createElement('p');
const div = document.createElement('div');
div.classList.add('child-node')
moviePoster.src = data.Poster;
movieName.innerHTML = `Name: ${data.Title}`;
movieYear.innerHTML = `Year: ${data.Year}`;
movieRatings.innerHTML = `Ratings: ${data.imdbID}`;
div.append(moviePoster,movieName,movieYear,movieRatings);
dataDiv.append(div);
});
}