I'm on my way to build web with TMDB webAPI, but i found out they use different variable for tv series and movies in trending section, tv use name and movie use title so there's will be undefined one. For newbie like me, i choose to use if else condition in function with return value, but it seems still not working.
const renderTrending = (results) => {
const listTrendingElement = document.querySelector("#trendingNow");
listTrendingElement.innerHTML = "";
results.forEach(result => {
const combine;
function _combine(){
if(result.name===undefined){
return combine = result.title;
} else {
return combine = result.name;
}
}
_combine();
listTrendingElement.innerHTML += `
<div class="col-2">
<div class="card">
<img class="card-img-top" src="${posterTMDB}w185${result.poster_path}" alt="Poster">
<div class="card-body">
<h5 class="card-title">${combine}</h5>
<div>
<!-- <span class="genre">${result.genre_ids}</span>-->
<span class="media-type">${result.media_type}</span>
</div>
</div>
</div>
</div>
`;
});
}
or maybe there's more effective way to do this?
Aucun commentaire:
Enregistrer un commentaire