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

200
Vistas
Want to trigger an adding score adding effect in JS

I want to make a trigger an adding score effect when user's score changing.

Here is the code I currently have:

let speed = 200;
let div = document.querySelector('div')
let olddiv = parseFloat(div.textContent)
let interval;
function change(increase){
   let add = increase/speed

   interval = setInterval(function(){
    div.textContent = parseFloat(div.textContent) +add;
    if(div.textContent > olddiv + increase){
        div.textContent = olddiv+ increase
        window.clearInterval(interval)
    }
   },1)
}
change(5000)
<div>1000</div>

The code works fine but I add 25 (increase/speed value) per milliseconds.

I want to make the score adding 1 every times. I tried to use for loop, but for loop will not shows the adding effect.

Also, since the setInterval doesn't accept milliseconds lower than 1, I can't use this code as well (this code will execute 1 ms every time which is too slow.

   let speed = 200;
    let div = document.querySelector('div')
    let olddiv = parseFloat(div.textContent)
    let interval;
    function change(increase){
       let addspeed = speed/increase;
       interval = setInterval(function(){
        div.textContent = parseFloat(div.textContent) +1;
        if(div.textContent > olddiv + increase){
            div.textContent = olddiv+ increase
            window.clearInterval(interval)
        }
       },addspeed)
    }
    change(5000)
<div>1000</div>

Could anyone give me any solution of solving this problem?

Thanks for any responds!

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