25+5 Clock fails only two tests

Hey looking for some feedback or someone to review my code .
Test fails #13 and #15 only, not really sure why. it says timer has not reached zero yet every other test passes when it asks for the timer to reach zero. I Tested this a million times now and its a pretty frustrating project. The intervals are being set to the values inside break and session lengths.

hello @devynj4722 why are you using custom timeout function with delay of your own

 const timeout = (milliseconds) => {
   return new Promise((resolve) => setTimeout(resolve, milliseconds));
 };
         

 timeout(800).then(() => {
             setRunBreak(true);
           });

when you can just use setInterval, refs and states for the app ?
setting a delay like this will definitely going to mess with the time.

Also you are using DOM elements for values instead of states

setBreakTime(
              Number(document.getElementById("break-length").textContent) * 60
            );

You are just complicating things unnecessarily.

Similar to you I also completed the project using functional component and useRef hook here

I always try to minimize the states and re-render count.
here is what I’ve planned :

states for reset - Break,Session

state for displaying formatted time - Time

state isRunning for Interval - play/pause/resume

state for typeOfTimer - Session/Break

IntervalID

label

<!-- Functions -->

break/session length modifies functions

fn to run on each interval

fn for handling PLAY/PAUSE/RESUME

fn for resetting APP

fn for AUDIO_CLIP

fn to format TIME
1 Like

Didn’t think of useRef because I’ve haven’t learned about it or used it before, the timeout function was because without it seems that the tests are going to fast and it doesn’t detect the timer reaching zero. the DOM element is pretty bad have to think of a better solution.

The fix was removing the time out promise. for some reason earlier I need those promises to pass the test now I guess I fixed what ever code was causing it and the timeout is was causing the problem thank you!

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