Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
Export value from function to global access

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
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda