Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda