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

226
Views
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
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!