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

196
Views
How do i make my timer restart everytime you lose in my game

the game code

How do i make my timer reset when you lose the game? here is a link to the game: https://editor.p5js.org/TobiasR/sketches/dvbIsv7Ah

Im new to programming and just recently started making my own game so any advice on how to make it better is appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have used system second in your code instead of that you can use the below code for creating a timer in your application.

let hr = 0, min = 0, sec = 0;
let intervalId = setInterval(() => {
    sec++;
    if(sec === 60) {
      min++;
      sec = 0;
      if(min === 60) {
        hr++;
        min = 0;
      }
    }
    console.log(`${hr}: ${min}: ${sec}`);
}, 1000);

Note: Don't forget to clearInterval(intervalId) when user lose the game. For using intervalId in other functions you have to declare it globally.

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!