I am trying to create two buttons, one is to select a genre that you want to watch which I have shown below. The second one is to randomize a title based on the genre chosen. But I am a little lost on how I would take the value of the chosenMovieGenre function into another function. Any help would be appreciated.
let changedGenre = document.getElementById('dropdown-movie').addEventListener('change', (event) => {
fetch("https://movies-tvshows-data-imdb.p.rapidapi.com/?type=get_random-movies&page=1")
.then(response => response.json())
.then(function chosenMovieGenre(jsonObject) {
let arrayGenres = jsonObject.movie_results
arrayGenres.forEach((title) => {
let genreChosen = event.target.value
if (title.genres[0] === genreChosen){
// console.log(title.title)
return title.title
}
})
})
.catch(err => {
console.error(err);
});
})