Https://www.codecademy.com/courses/learn-intermediate-javascript/projects/js-film-finder

Hi everybody, I have an issue in this exercise.

https://www.codecademy.com/courses/learn-intermediate-javascript/projects/js-film-finder

const tmdbKey = 'the key api number';
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);
      const genres = jsonResponse.genres;
      
      return genres;
    }

  }catch(error){

    console.log(error);

  }

};

const getMovies = async () => {
  const selectedGenre = getSelectedGenre();
  const discoverMovieEndpoint = '/discover/movie';

  const requestParams = `?api_key=${tmdbKey}&with_genres=${selectedGenre}`;

  const urlToFetch = `${tmdbBaseUrl}${discoverMovieEndpoint}${requestParams}`;

  try{
    const response = await fetch(urlToFetch);

    if(response.ok){

      const jsonResponse = await response.json();
      //console.log(jsonResponse);
      const movies = jsonResponse.results;
      console.log(movies);
      return movies;

    }


  }catch(error){

    console.log(error);
  };

};



const getMovieInfo = async (movie) => {

  const movieId = movie.id;
  const movieEndpoint = `/movie/${movieId}`;

  const requestParams = `?api_key=${tmdbKey}`;

  const urlToFetch = `${tmdbBaseUrl}${movieEndpoint}${requestParams}`;
  try{
    const response = await fetch(urlToFetch);
    if(response.ok){
      const jsonResponse = await response.json();
      const movieInfo = jsonResponse;
     
      return movieInfo;


    }

  }catch(error){
    console.log(error);
  };


};



// Gets a list of movies and ultimately displays the info of a random movie from the list
const showRandomMovie = async () => {
  const movieInfo = document.getElementById('movieInfo');
  if (movieInfo.childNodes.length > 0) {
    clearCurrentMovie();
  };
  const movies = await getMovies();
  const randomMovie = getRandomMovie(movies);
  const info = getMovieInfo(randomMovie);
  displayMovie(info);
};


getGenres().then(populateGenreDropdown);
playBtn.onclick = showRandomMovie;

I get a result of undefined when I run the program

1 Like

I get the same

I figured it out you are missing an await in your last function

Thank you very much…
Yes you are right, I had an “await” missing at the const info in the very last function, but well at the end of all of this, I don’t know what I learned, there are a lots of parts on this exercise that we don’t do them…
I apreciate your help…

1 Like