Jump to content

wallace4793

Members
  • Posts

    1
  • Joined

  • Last visited

wallace4793's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Hi, Im learning a little JS to use a home automation application that requires some low level coding, namely JS. I have what is probably a basic question. I want to test using a "for" loop and increment part of the device object name too. Is this possible. For example, my working code is : recent1id = (searchresult.result.movies[0].movieid) // EXTRACT MOVIE ID var r = http.get(('https://api.themoviedb.org/3/search/movie?api_key=') + (tvdbid) + ('&query=') + (searchresult.result.movies[0].title)) // EXTRACT MOVIE DETAILS FROM TVDB var json = r.data; // RECEIVE FEEDBACK device.MovieThumb1 = ("http://image.tmdb.org/t/p/original" + (json.results[0].poster_path)); // ASSIGN POSTER device.MovieTitle1 = (searchresult.result.movies[0].title) recent2id = (searchresult.result.movies[1].movieid) // EXTRACT MOVIE ID var r = http.get(('https://api.themoviedb.org/3/search/movie?api_key=') + (tvdbid) + ('&query=') + (searchresult.result.movies[1].title)) // EXTRACT MOVIE DETAILS FROM TVDB var json = r.data; // RECEIVE FEEDBACK device.MovieThumb2 = ("http://image.tmdb.org/t/p/original" + (json.results[0].poster_path)); // ASSIGN POSTER device.MovieTitle2 = (searchresult.result.movies[1].title) The 2 portions of code simply extract a movie title and pull the images from TMDB and assign to my device object - is it possible to increment the process using the for loop? How I imagine it might work is below..... where variable "i" replaces the values I want to increment through the loop. for (i = 0; i < 5; i++) { recent[i+1]id = (searchresult.result.movies[i].movieid) // EXTRACT MOVIE ID var r = http.get(('https://api.themoviedb.org/3/search/movie?api_key=') + (tvdbid) + ('&query=') + (searchresult.result.movies[i].title)) // EXTRACT MOVIE DETAILS FROM TVDB var json = r.data; // RECEIVE FEEDBACK device.MovieThumb[i +1] = ("http://image.tmdb.org/t/p/original" + (json.results[i].poster_path)); // ASSIGN POSTER device.MovieTitle[i + 1] = (searchresult.result.movies[i].title) } Be kind.. its my first post 🙂
×
×
  • Create New...