Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda