Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!