Hi! I for some reason I’m stuck on getting step 11 to work and cannot get the genres array to log to the console, here’s my code.
const tmdbKey = 'xxxxxxxxxxxxxxxxxxxxxx';
const tmdbBaseUrl = 'https://api.themoviedb.org/3';
const playBtn = document.getElementById('playBtn');
const getGenres = async () => {
const genreRequestEndpoint = "/genre/movies/list";
const requestParams = `?api_key=${tmdbKey}`;
const urlToFetch = `${tmdbBaseUrl}${genreRequestEndpoint}${requestParams}`;
try {
let response = await fetch(urlToFetch, { method: "GET"});
if (response.ok) {
const jsonResponse = await response.json();
console.log(jsonResponse);
let genres = jsonResponse.genres;
return genres;
}
} catch (err) {
console.log(err);
}
};
const getMovies = () => {
const selectedGenre = getSelectedGenre();
};
const getMovieInfo = () => {
};
// Gets a list of movies and ultimately displays the info of a random movie from the list
const showRandomMovie = () => {
const movieInfo = document.getElementById('movieInfo');
if (movieInfo.childNodes.length > 0) {
clearCurrentMovie();
};
};
getGenres().then(populateGenreDropdown);
playBtn.onclick = showRandomMovie;
Here’s the error:
Uncaught (in promise) TypeError: genres is undefined