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

227
Visualizações
Calling function only once after 60 secondds

I have a function that calculates the users words per minute (wpm), it should only be called once after 60 seconds. At the moment I am using if statements and setTimeout, but not getting the desired result.

wpm logic

function wordsdPerMinute() {
  if (userInput.toLocaleLowerCase() + ', ' == wordArray[wordCount]) {
    set_wordCount(wordCount + 1)
  }

  if (functionCounter == 0) {
    let timeOutID = setTimeout(() => {
      set_funcitonCounter(functionCounter + 1)
      alert('Times up!, press "Check your highscore!" downbelow')
    }, 60000)
    clearTimeout(timeOutID)
  }
  else {
    
    set_funcitonCounter(functionCounter - 1)
    wpmCounter()
  }
}

function wpmCounter() {
  countWPM = (wordCount + 1) / 60;
  highscore.push(countWPM)
  highscore.sort(function(a,b) {return b-a})
}

How the function is called

<TextInput style={styles.inputText} onChangeText={set_userInput} value={userInput} onKeyPress={(event) => {
        if (event.nativeEvent.key == ' ') {
          wordsdPerMinute()
        }
        () => set_reset(initialState)
      }}

The result I am getting is the wpmCounter() is executed as many times as it is called after 60 seconds seconds. How can i call the wpmCounter() function only once after 60 seconds?

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