-1
Good evening! I cannot access the title property inside the films as I do to make this request?
Planet: Hoth
Total population: USSR
Climate: Frozen
Land: tundra, ice caves, mountain ranges
Movie appearance: https://swapi.co/api/films/2/
this is the return I have of the request but wanted to return the name of the films in question. I have already researched here and in other forums but I could not solve yet. in case someone can help me I am grateful. vlw guys!
code:
function getPlanet() {
let randomNumber = Math.floor(( Math.random() * 10 ) + 1 )
let apiUrl = 'https://swapi.co/api/planets/' + randomNumber
// integrando API para adicionar a função getPlanet;
axios.get (apiUrl).then(( function ( response ) {
updateInfo (response.data)
} ))
}
function updateInfo(data) {
name.innerText = 'Planeta: ' + data.name;
population.innerText = 'População total: ' + data.population;
climate.innerText = 'Clima: ' + data.climate;
terrain.innerText = 'Terreno: ' + data.terrain;
films.innerText = 'Aparição em filmes: ' + data.films.title;
}
// Evento Click;
button.addEventListener('click', getPlanet);
I don’t understand. You’re making the requisition for
https://swapi.co/api/films
or tohttps://swapi.co/api/planets
? Where in your code you access this propertytitle
that I’m not seeing?– Andre
So. i do the request for Planets, and inside this Planets has the property 'films' that returns me an api link and inside this api has the title property that returns the name of the movies in which this particular planet appeared. " films.innerText = 'Movie appearance: ' + data.films.title;" sorry I have not edited my code correctly. vlw by feed!
– Joao Paulo Gardiano