function incrementStats() {
const counters = document.querySelectorAll('.counter');
counters.forEach((counter) => {
counter.innerText = 0;
const updateCounter = () => {
const target = +counter.getAttribute('data-target'); // the "+" here casts the returned text to a number
const c = +counter.innerText;
const increment = target / 200;
if (c < target) {
counter.innerText = Math.ceil(c + increment);
setTimeout(updateCounter, 1);
// here the function is calling itself until "c"
// reaches the "data-target", making it recursive
} else {
counter.innerText = target;
}
};
updateCounter();
});
}
document.addEventListener('DOMContentLoaded', incrementStats);