I'm trying to create an app that should get an array of movies (using tmdb API) and when the button is clicked, the value of index increase so we can see the next one. My ideia is export the new value of my var (after cardBtn was clicked) to global access, so my function setImage can get it and change the index of my array based on it. This is my code:
cardBtn.addEventListener('click', count)
var count = 0
fetch(movieUrl)
.then(resp=>
resp.json()
)
.then(data => {
setImage(0, data.results) // 0 is the index, I want to make it a variable that the function count edits everytime cardBtn is clicked
})
function setImage(actual, data){
cardImg.src=`${img}${data[actual].backdrop_path}`
cardTitle.innerHTML = `${data[actual].original_title}`
cardText.innerHTML = `${data[actual].overview}`
}
function count(){
count += 1
}