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

199
Views
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
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!