edysegura / js-callback

A simple example to demonstrate how to use callback in JavaScript using image HTML element

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Progress bar is not working as expected

edysegura opened this issue · comments

As we are defining a new closures to each created image it is not working as expected!

function updateProgressbar() {
const progressBar = document.querySelector('progress')
const progressPercentage = document.querySelector('span')
const total = pokemonsNumber.length
let loaded = 0
return () => {
++loaded
let percentage = Math.floor((loaded * 100) / total)
progressBar.value = percentage
progressPercentage.textContent = percentage + '%'
}
}

image.addEventListener('load', updateProgressbar())