-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (48 loc) · 1.6 KB
/
Copy pathscript.js
File metadata and controls
56 lines (48 loc) · 1.6 KB
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
let inp= document.querySelector('.movie-name');
let searchBtn= document.querySelector('.search-btn');
let result= document.querySelector('.result');
async function getMovie(){
const key= "9f8283fe";
let url = `https://www.omdbapi.com/?apikey=${key}&t=${inp.value}&page=1`;
if(inp.value === ""){
result.innerHTML= `
<h3 class = 'msg'>Please enter a movie name</h3>
`;
}
else{
const response = await fetch(url);
const data = await response.json();
console.log(data);
result.innerHTML=`
<div class="info">
<img src=${data.Poster} class="poster">
<div>
<h2>${data.Title}</h2>
<div class="rating">
<img src="https://cdn-icons-png.flaticon.com/128/889/889118.png">
<h4>${data.imdbRating}</h4>
</div>
<div class="details">
<span>${data.Rated}</span>
<span>${data.Year}</span>
<span>${data.Runtime}</span>
</div>
<div class="genre">
<div>${data.Genre.split(",").join("</div><div>")}</div>
</div>
</div>
</div>
<h3>Plot:</h3>
<p>${data.Plot}</p>
<h3>Cast:</h3>
<p>${data.Actors}</p>
`;
}
}
searchBtn.addEventListener('click', getMovie);
window.addEventListener('keydown', (e)=>{
if(e.key === 'Enter'){
getMovie();
}
}
);