Film Finder Project: genre is undefined

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
// You wrote:
const genreRequestEndpoint = "/genre/movies/list";

// It should be:
const genreRequestEndpoint = "/genre/movie/list";

Ahh you’re right, thank you!

1 Like

hi!
I am stuck in the step no. 11 of the ‘Film Finder Project’. If you can please help.
const tmdbKey = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’;
const tmdbBaseUrl = ‘https://api.themoviedb.org/3’;
const playBtn = document.getElementById(‘playBtn’);

const getGenres = async() => {
const genreRequestEndpoint = ‘/genre/movie/list’;
const requestParams = ?api_key=${tmdbKey};
const urlToFetch = ${tmdbBaseUrl}${genreRequestEndpoint}${requestParams};
try{
const response = await fetch(urlToFetch);
if (response.ok){
const jsonResponse = await response.json();
console.log(jsonResponse);
}
}
catch(error){
console.log(error);
}
};

step 11 would be

const genres = jsonResponse.genres;
console.log(genres);

step 12 would be

return genres;
2 Likes

Thank You. It’s working.