Front-End Development - Film Finder project

There are no active topics for this project. Let’s discuss it here.
link to the project: link

Interested in solving problem #28 (challenge).
How to change the page?

" 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, update getMovies() so that movies contains results from a random page instead of the first page."

I was trying to change the page to a random one to get access to other movies. But in fact, only the value of .page changed in the object. At the same time, the films offered remained the same (it is easy to check by the IP of the film).

My function getMovies():

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 randomPage = Math.ceil(Math.random() * jsonResponse.total_pages);      
      jsonResponse.page = randomPage;      // it doesn't work
      const movies = jsonResponse.results;           
      return movies;
    }
  }catch(error){
    console.log(error);
  }
};

So what is the right way to change the page so that other films would be offered to us?
@mtrtmk could you help me pls

I don’t have access to the project, but

const randomPage = Math.ceil(Math.random() * jsonResponse.total_pages); 

will assign an integer to randomPage, which you are then assigning to jsonResponse.page. So, it is understandable that only the value of the page is being changed in the jsonResponse object. Just assigning a new value to page won’t automatically change the results.

Instead, you should have a look at this thread (in particular janbazant1107978602’s post regarding the page query parameter):

https://discuss.codecademy.com/t/film-finder-last-challenge/675751

2 Likes