The Movie Database Support

Sorry for asking this question, im new to using api´s and i have seen alot of questions on here.


We are making a project, in which we want to fetch 1 movie by a genre chosen by the user. When the user then clicks the button, one movie will appear, if the user isn´t happy with the recommended movie, the user can fetch another movie.. is this possible with TMDB api. thx in advance

fetch('https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc&with_genres=9648', options)
  .then(response => response.json())
  .then(data => {
    if (data.results && data.results.length > 0) {
      const randomIndex = Math.floor(Math.random() * data.results.length); // Generer en tilfældig indeks
      const tilfældigFilm = data.results[randomIndex]; // Hent den tilfældige film

      if (tilfældigFilm.id) {
        console.log('Tilfældig film ID:', tilfældigFilm.id);
      } else {
        console.log('Ingen ID fundet for den tilfældige film.');
      }
    } else {
      console.log('Ingen resultater fundet');
    }
  })
  .catch(err => console.error(err));

i have tried doing this, but for some reason it returns 2 movies in the consol log

Can't find a movie or TV show? Login to create it.

Want to rate or add this item to a list?

Login