-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (47 loc) · 1.73 KB
/
script.js
File metadata and controls
59 lines (47 loc) · 1.73 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
//API KEY
const API_KEY= 'ecdb4cd2'
const searchInput= document.querySelector('#searchInput');
const searchButton= document.querySelector("#searchButton");
const movieTitle= document.querySelector("#movieTitle");
const movieYear= document.querySelector("#movieYear");
const movieDetailsbtn= document.querySelector("#movieDetailsbtn");
const viewLessbtn= document.querySelector("#viewLessbtn");
function getData(url){
fetch(url)
.then((response)=> response.json())
.then((data)=>{
console.log('Data:', data);
movieTitle.innerHTML= "Title : " + data.Title
movieYear.innerHTML= "Year : " + data.Year
+ "<div>" + data.Language +"</div>"
+ "<div>" + data.Country +"</div>"
moviedetails.innerHTML= "Cast : "+ data.Actors
+ "<div>" + "Collection : " + data.BoxOffice +"</div>"
+"<div>" + "Genre : " + data.Genre +"</div>"
+ "<div>"+ "Director : " + data.Director +"</div>"
})
.catch(err=> console.log(err))
}
//fetch data from the api
searchButton.onclick=function(event){
event.preventDefault();
const value=searchInput.value;
const url="http://www.omdbapi.com/?t="
//generate the url based on the user input
const newUrl= url + value + "&apikey=" + API_KEY;
console.log(newUrl)
getData(newUrl);
}
//toggle between the buttons to hide and show details
movieDetailsbtn.onclick=(()=>{
console.log("show")
moviedetails.style.display= "block";
movieDetailsbtn.style.display= "none";
viewLessbtn.style.display="block";
})
viewLessbtn.onclick=(()=>{
console.log("hide")
moviedetails.style.display= "none";
movieDetailsbtn.style.display= "block";
viewLessbtn.style.display= "none";
})