Film finder does not log any movie recommendetions

Hi! I just finished coding this exercise. The code didn’t manage to generate movie info by clicking the button or to get the dropdown to work. Here is my code.

const tmdbKey = ‘’;

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 = response.json();

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){

jsonResponse = response.json();

const movies = jsonResponse.results;

return movies;

}

}

catch(error){

console.log(error);

}

};

const getMovieInfo = async (movie) => {

const movieId = movie.id;

const movieEndpoint = ‘/movie/${movie.Id}’

};

const requestParams = ?api_key=${tmdbKey};

const urlToFetch = ${tmdbBaseUrl}${movieEndpoint}${requestParams};

try{

const response = await fetch(urlToFetch);

if(response.ok){

const movieInfo = response.json();

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 = await getMovieInfo(randomMovie);

displayMovie(info);

};

getGenres().then(populateGenreDropdown);

playBtn.onclick = showRandomMovie;

Are you getting an error? Or is the desired functionality just not occurring? Also, could you edit your post and use the </> button to format your code?

You seem to have a }; in the wrong place in the getMovieInfo function.
The }; should be after the console.log(error);

1 Like

Yes, i get this message in the console:
unnamed

I solved the problem, it works perfect now !
Thank you for all the responds and help!

So how did you solve it?(I have message only about “genres is not iterable”)

I also solved it. For people who have the same problem. In “helpers.js” you need to access genres like “genres.genres”. But as I solved it, I’ve got new problems lol.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.