forked from mbarrientos1129/mighty-mustangs-Project-1-Group
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovieLogic.js
140 lines (127 loc) · 5.24 KB
/
movieLogic.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var randomMovieBtn = document.querySelector('#random-movie')
var searchMovieBtn = document.querySelector('#movie-search')
var movieTitle1 = document.querySelector('#movie-title-1')
var movieTitle2 = document.querySelector('#movie-title-2')
var movieTitle3 = document.querySelector('#movie-title-3')
var movieTitle4 = document.querySelector('#movie-title-4')
var movieImages = [
movieImage1,
movieImage2,
movieImage3,
movieImage4
]
var movieImage1 = document.querySelector('#movie-image-1')
var movieImage2 = document.querySelector('#movie-image-2')
var movieImage3 = document.querySelector('#movie-image-3')
var movieImage4 = document.querySelector('#movie-image-4')
var moviePlot = document.querySelector('#movie-plot')
var allMovies = ["Red Notice", "Predator", "The Green Mile", "I,Robot", "The Giver", "Scream 4",
"The Conjuring", "The Conjuring 2", "Annabelle", "Annabelle: Creations",
"The Conjusring: The Devil Made Me Do It", "The Nun", "Annabelle Comes Home",
"The Curse of La Llorona", "28 Days Later", "28 Weeks Later", "The Grudge",
"The Gallows", "The Rite", "Incarnate", "Eternals", "Iron Man",
"Iron Man 2", "Thor", "Capitan America: The First Avenger", "Marvel's The Avengers",
"Iron Man 3", "Thor: The Dark World", "Capitan America: The Winter Solider",
"Guardians of the Galaxy", "Averngers: Age of Ultron", "Ant-Man", "Capitan America: Civil War",
"Doctor Strange", "Guardians of the Galaxy Vol. 2", "Spider-Man: Homecoming",
"Thor: Ragnarok", "Black Panther", "Avengers: Infinity War", "Ant-Man and the Wasp",
"Capitan Marvel", "Avengers: Endgame", "Spider-Man: Far From Home", "The Waterboy",
"Big Daddy", "Happy Gilmore", "Horrible Bosses", "Horrible Bosses 2", "Mr. Deeds",
"Our Idiot Brother", "The Benchwarmers", "I Am Sam", "The Dig",
"The Last Duel", "King Richard", "Cherry", "tick, tick...BOOM!", "Rush",
"Marriage Story", "Steve Jobs", "The Theory of Everything",
"The Longest Yard", "Billy Madison", "Anger Managment", "You Don't Mess with the Zohan",
"Little Nicky", "The Matrix", "Step Brothers", "I Am Legend", "Shutter Island",
"The Social Network", "Fast and Furious", "Free Guy", "The Suicide Squad", "Luca", "Mortal Kombat",
"The Unholy", "Sonic the Hedgehog 2", "Nobody", "Deadpool", "Deadpool 2", "Sonic the Hedgehog",
"Ted", "Ted 2", "Toy Story", "Toy Story 2", "Toy Story 3", "Toy Story 4", "House of Gucci",
"Shrek", "Venom", "Love & Other Drugs", "The Wolf of Wall Street", "Fatherhood", ""
]
//Movie 1
function getRandomMovie1() {
var randomIndex = Math.floor(Math.random() * allMovies.length);
var movieName = allMovies[randomIndex]
var movieUrl = 'https://www.omdbapi.com/?t=' + movieName + '&apikey=21149232'
fetch(movieUrl)
.then(response => {
return response.json()
})
.then(data => {
movieImage1.src = data.Poster
movieTitle1.textContent = data.Title
})
allMovies = allMovies.filter(movie => {
return movie !== movieName;
})
}
//Movie 2
function getRandomMovie2() {
var randomIndex = Math.floor(Math.random() * allMovies.length);
var movieName = allMovies[randomIndex]
var movieUrl = 'https://www.omdbapi.com/?t=' + movieName + '&apikey=21149232'
fetch(movieUrl)
.then(response => {
return response.json()
})
.then(data => {
movieImage2.src = data.Poster
movieTitle2.textContent = data.Title
})
allMovies = allMovies.filter(movie => {
return movie !== movieName;
})
console.log(allMovies)
}
//Movie 3
function getRandomMovie3() {
var randomIndex = Math.floor(Math.random() * allMovies.length);
var movieName = allMovies[randomIndex]
var movieUrl = 'https://www.omdbapi.com/?t=' + movieName + '&apikey=21149232'
fetch(movieUrl)
.then(response => {
return response.json()
})
.then(data => {
movieImage3.src = data.Poster
movieTitle3.textContent = data.Title
})
allMovies = allMovies.filter(movie => {
return movie !== movieName;
})
}
//Movie 4
function getRandomMovie4() {
var randomIndex = Math.floor(Math.random() * allMovies.length);
var movieName = allMovies[randomIndex]
var movieUrl = 'https://www.omdbapi.com/?t=' + movieName + '&apikey=21149232'
fetch(movieUrl)
.then(response => {
return response.json()
})
.then(data => {
movieImage4.src = data.Poster
movieTitle4.textContent = data.Title
})
allMovies = allMovies.filter(movie => {
return movie !== movieName;
})
}
var setMovies = function() {
getRandomMovie1()
getRandomMovie2()
getRandomMovie3()
getRandomMovie4()
}
randomMovieBtn.addEventListener("click", setMovies)
setMovies();
var getMoviePlot = function(titVal) {
var requestUrl = 'https://www.omdbapi.com/?t=' + titVal + '&apikey=21149232';
fetch(requestUrl)
.then(function(response) {
return response.json();
})
.then(function(data) {
moviePlot.textContent = "";
moviePlot.textContent = data.Plot;
})
}