Code Error with Film Finder Project

Hello,
I have been trying to find why the project is working but I haven’t found the problem. I have even looked through some of the forum topics that people posted with the error code that is the same as mine but their solutions are not the problem with my code. Could anyone be able to help me figure out what is causing the error?

image

Here is my code:

const tmdbKey = "(HAVE THE API KEY JUST REMOVED IT FROM POST)"; 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(); const genres = jsonResponse.genres; //console.log(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 reponse = await fetch(urlToFetch); if (response.ok) { const jsonResponse = await response.json(); const movies = jsonResponse.results; 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 movieInfo = await 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;
1 Like

You have a typo in the getMovies function (on line 29 in the Codebyte).

const reponse = await fetch(urlToFetch);

Here, reponse should be response

1 Like

OMG Thank you @janbazant1107978602!!!
Literally was racking my brain for two days trying to figure out the error :joy:
It is working fine now.

Hey Guys, I seem to have the same kinf of problem as colesa09, meaning Uncaught (in promise) TypeError. Only that in mine it couldn’t read properties of undefined (reading poster_path).
The program runs right up to the selection of genres and the button itself is active although that’s about it. I’ve spent several hours debugging it and I seem to be unable to find anything wrong with it.
Any help would be highly appreciated

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}`; //console.log(urlToFetch) 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(); const movies = jsonResponse.results; 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 movieInfo = await 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;

In your Codebyte, line 48 is being underlined/highlighted with the message:

// Line 48
const response = await fetch(UrlToFetch);

// Warning Message
Could not find name 'UrlToFetch'. Did you mean 'urlToFetch'?

Notice the three dots on line 48. When you hover above them, the message alerts you to the typo.

Also on line 46, urlToFetch is grayed out. When you hover above it, the message appears:

'urlToFetch' is declared but its value is never read.

When you fix line 48, the message from line 46 will also disappear.

2 Likes

This is a very cool feature… Thank you so much for your help! :slight_smile:

1 Like