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.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login