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
How do i make a countdown loop

I need to make a clicker game and in it i need an upgrade that adds clicks per seconds. How do i make a loop that every second it adds to the points variable? this is in JavaScript by the way. I have tried googling an answer and that did not help, an anyone help me with this?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Do you want the clicks per seconds feature? I am not sure what exactly you looking for.
as Aviv Ben Shahar already answered to use setInterval.

here is the code you might looking for.

const clicksdom = document.getElementById("clicks");
const hclicksdom = document.getElementById("hclicks");
var clicks=0;
var hclicks=0;
document.addEventListener("click",()=>{
  clicks+=1;
});
const intervalId = setInterval(()=>{
  if(clicks>=hclicks){
    hclicks = clicks;
  }
  hclicksdom.innerText = hclicks;
  clicksdom.innerText = clicks;
  clicks = 0;
}, 1000) 
<div>
  <p>Clicks Per Seconds</p>
  <p>highest cps <span id="hclicks">--</span></p>
  <p>current cps <span id="clicks">--</span></p>
</div>

// To kill the interval loop
clearInterval(intervalId)
about 4 years ago · Juan Pablo Isaza Report

0

const intervalId = setInterval(()=>{
   ... DO STUFF HERE
  
}, 1000) // will happened every 1000 milliseconds 


// To kill the interval loop
clearInterval(intervalId)

about 4 years ago · Juan Pablo Isaza Report
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!