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

304
Views
Javascript Stopwatch that changes color every 10 seconds

Beginner JS project, got everything to work but I wanted to play around with colors. Looking to get the timer to change colors every 10 seconds. I thought a basic function would work but apparently not. I know I'm doing something wrong somewhere but I cant figure it out.

window.onload = function () {
  let seconds = 00;
  let tens = 00;
  const roundTens = $("#tens");
  const roundSeconds = $("#seconds");
  const buttonStart = document.getElementById("button-start");
  const buttonStop = document.getElementById("button-stop");
  const buttonReset = document.getElementById("button-reset");
  let Interval;

  buttonStart.onclick = function () {
    clearInterval(Interval);
    Interval = setInterval(startTimer, 10);
  };

  buttonStop.onclick = function () {
    clearInterval(Interval);
  };

  buttonReset.onclick = function () {
    clearInterval(Interval);
    tens = "00";
    seconds = "00";
    roundTens.text(tens);
    roundSeconds.text(seconds);
  };

  function colorChange(color1, color2) {
    if (color1.value === "00" && color2.value === "59") {
      color1.style.color = "orange";
      color2.style.color = "red";
    } else if (color1.value === "00" && color2s.value === "00") {
      color1.style.color = "green";
      color2.style.color = "blue";
    }
  }

  function startTimer() {
    tens++;

    if (tens <= 9) {
      roundTens.text("0" + tens);
    }

    if (tens > 9) {
      roundTens.text(tens);
    }

    if (tens > 99) {
      console.log("seconds");
      seconds++;
      roundSeconds.text("0" + seconds);
      tens = 0;
      roundTens.text("0" + tens);
    }

    if (seconds > 9) {
      roundSeconds.text(seconds);
    }
  }
  colorChange();
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

startTimer should call colorChange (currently never called)

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!