Hello.
I’ve finished the “Film Finder” project. I’d like to tackle the third challenge, but I’m in need of a hint.
The challenge reads,
“Our API call inside of
getMovies()
returns many pages of results, but currently our program only randomizes results from the first page. To randomize our results even more, updategetMovies()
so thatmovies
contains results from a random page instead of the first page.”
Here is the code from the relevant function:
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);
}
};
When I console.log(jsonResponse), I get this:
1. Object
1. page: 1
2. results: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
3. total_pages: 1667
4. total_results: 33328
So I can see that 1667 pages have returned. But this result is only showing the first. So it seems to have already been filtered down to a single page at this point.
So I take one step back and console.log(response) from the previous line. Now I can no longer see the page or the total_pages. So I’m not sure what else I might be able to try from here.
Thanks in advance for any insight!