25+5 clock - i cant pass tests 19,20,21. Help me with this problem

test numbers 19,20 ,21 and keeps failing. I’m really stuck here and have no idea what I’m supposed to do next. Been checking the code thoroughly too. Here’s the link to my code,

Here’s a snap of the failing tests

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Build a 25 + 5 Clock

Link to the challenge:

There is a delay in your timer starting, I estimate 2 second and some between ‘25:00’ and ‘24:59’. This I’m unsure of the cause.

Each second of yours is also inconsistent in length of time passed. I believe this is because you used setInterval as is to recursively trigger recalculation of the time left.

But setInterval does not necessarily run and finish at the time parameter you pass in, instead of evoking recalculation every 1000ms, setInterval can do it at 1040ms now, and perhaps 1006ms next. This is because setInterval executes the callback no less than time apart.

You need to find a way to generate accurate times that are 1000ms on the dot.

1 Like

Is there a way to achieve what your suggesting?
or do i need to restructure my code for that?

As @MatchaCrisp mentioned, it takes two seconds to go from 25:00 to 24:59. This is because initially this.state.currentPlay is set to an empty string (""). Then inside sessionTimer() you check if this.state.currentPlay is equal to an empty string and you set this.state.currentPlay to "session". But you don’t decrement the timer.

sessionTimer() is called every second (not exactly every second as @MatchaCrisp mentioned; but close enough for this exercise). So the first call (after 1 second) sets this.state.currentPlay to "session" and then the second call (after 2 seconds) decrements the timer for the first time.

2 Likes

Both of you guys are awesome, i owe it to both @MatchaCrisp and @BenGitter
I fixed it !!!
added an or logic in the else if (this.state.currentPlay == "session")which looks like else if (this.state.currentPlay == "session"||this.state.currentPlay == "") and seperated the final else if into an if like this,

if (this.state.currentPlay == "") {
     this.setState({
       currentPlay: "session"
     });
   }

So it’s working now

1 Like

I did not realize accurate seconds were not absolutely required, I apologize for leading you down a rabbit hole there. But if you are still interested in how it might be done, the example by FCC in fact has a function AccurateInterval that achieves this.

2 Likes

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