25 + 5 Clock Timer does not reach 00:00

I am trying to complete the FreeCodeCamp 25 + 5 clock project with React. When I website runs the project tests, it says that the timer is not reaching 00:00, even though when I click play, it clearly reaches 00:00.

I am wondering if I am having this issue because of some sort of drifting? How would I go about fixing that?

Thank you.

Codepen: https://codepen.io/Jamece/pen/jOazYvQ

I didn’t debug it completely, but unfortunately, it’s not clock drift since all the tests are run in your browser with your local clock and none of the code could run long enough to even cover a second.

There are a few things I noticed:

  1. The tests take run in real time and shouldn’t. The tests are built to fast-forward through some parts and if they can’t there’s something wrong with the time parts of the project.
  2. You don’t consistently use functions to set the state and you really should.
  3. When I manually change the time intervals and start the clock, it resets to 25/5 and starts, even if I start with something like 6/2. Your break/session timer functions are using the timeLeft state while the increment/decrement functions are setting sessionLength/breakLength and the changes are not reflected across components.

My guess is the problem lies in making sure that all the time components are using and changing the time same state values in consistent ways.

I solved it. The Date.now was messing me up. I removed that and instead had the timer decrement the timer length passed into the function. And still used set interval.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.