-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (56 loc) · 2.51 KB
/
Copy pathscript.js
File metadata and controls
77 lines (56 loc) · 2.51 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
async function serachMovie(movieName) {
let url = `https://www.omdbapi.com/?s=${movieName}&apikey=a6606658`
try {
const response = await fetch(url)
const data = await response.json()
const movieContainer = document.getElementById("movieContainer")
movieContainer.innerHTML += " "
if (data.Response === "True") {
console.log(data)
data.Search.forEach(movie => {
movieContainer.innerHTML += `
<div class="movie">
<img src = ${movie.Poster !== "N/A" ? movie.Poster : "https://via.placeholder.com/100"}
<div>
<div>
<h3><b>${movie.Title}</b><h3>
<p><b>${movie.Year}</b></p>
</div>
`
movieContainer.style.textAlign = "left";
movieContainer.style.fontWeight = "bold";
})
} else {
movieContainer.innerHTML = "<p>NO MOVIE FOUND!</p>";
movieContainer.style.color = "black";
movieContainer.style.fontSize = "20px";
movieContainer.style.fontWeight = "bold";
movieContainer.style.textAlign = "center";
movieContainer.style.marginTop = "20px";
movieContainer.style.fontFamily = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif";
}
} catch (error) {
console.log(error)
}
}
function handlesearch() {
const movieName = document.getElementById("movieInput").value
if (movieName) {
serachMovie(movieName)
}
}
function handleKeyPress(event) {
if (event.key === 'Enter') {
handlesearch();
}
}
document.getElementById("movieInput").addEventListener("keypress", handleKeyPress);
function clearInput() {
document.getElementById("movieInput").value = '';
document.getElementById("movieContainer").innerHTML = '';
}
document.getElementById("movieInput").addEventListener("input", function () {
if (this.value === '') {
clearInput();
}
});