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

244
Views
JS How to count seconds to make bot do an operation every second

I am trying to make a cookie clicker game, and one item that you can get in shop is a bot where it adds x amount of credits to your current amount of credits every second. I want to be able to make multiple of these bots with variations, so not sure if setInterval would be usable in this case. How can I make this? Note: The timer only starts when a variable is turned to false, so the timer shouldn't start when the app is opened. P.S. I am using React

let bought = false
const [credits, setCredits] = useState
if (bought) {
   For every second {
     setCredits(credits+1)
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you have to calculate seconds after each reaction on click, you should use setInterval() in JavaScript function.

Example --

let time = document.getElementById("time");
function clock(){
    let date = new Date();
    let clocktime = (date.toString().split('G')[0]);
    time.innerHTML = `${clocktime}`;
}
setInterval(clock, 1000);

First target an element then change its text to this function's output, and give time here in setInterval() function, for how many seconds you want to repeat that function (for how many seconds)

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!