25 pomodoro clock 3 left errors i can't fix yet HELP!

Hey gues i have 3 left errors to fix , but i couldn’t find a solution here is the project code : codepen
please don’t mind the simple ui , i haven’t started the css part yet
Thanks in advance

Try logging out console.log(minute + ":" + second) inside the formatIt function.

I didn’t look at the Session/Break label test fail yet.


Side note:

// 0 : disabled, 1 : running, 2 : paused

If you have to add the meaning of a number to a comment you are using magic numbers. Instead of using magic numbers, I would suggest strings or booleans.

I would also suggest a bit clearer variable names, setsRunning and setbRunning are visually very similar.

Here are my observations.

  1. Your three remaining errors are all related to changing the break/session label/length value and time-label value. I noticed that when the app starts, the display is 05:00 but it should be 25:00. When I clicked the reset button, it goes to 25:00. When I click reset doing the Break mode, the display goes back wrongly to 05:00. If you fix this behavior, all three errors could go away.

  2. I started reading your code and see if I can find why this behavior is happening. I stopped because the code is difficult to follow. I suggest the following changes. It really will help clean the code and makes it more readable and much much easier to debug.
    a. Just use one counter to keep track of remaining time. Switch the value for this counter to break length or session length depending on the state of the clock. Keeping track of two variables makes the logic much harder. For example, this one

  const handleit = () => {
    if (sRunning === 0 && bRunning === 0) {
      setsRunning(1);
    } else if (sRunning === 1 && bRunning === 0) {
      setsRunning(2);
    } else if (sRunning === 2 && bRunning === 0) {
      setsRunning(1);
    } else if (sRunning === 0 && bRunning === 1) {
      setbRunning(2);
    } else if (sRunning === 0 && bRunning === 2) {
      setbRunning(1);
    }
  

(and others) will be much cleaner and much easier to read.

b. Use better identifiers and constants.

const STOPPED = 0
const RUNNING = 1
const PAUSED = 2
. . .
sessionState = STOPPED
breakState = RUNNING

//or
let isClockRunning = true

(Note: if you use just one counter, then you need clockState to be BREAK or SESSION and set this counter timeLeft to either breakLength or sessionLength)

1 Like

thank u very much i will try to make it more cleaner

alright thnx for the feedback i will try to fix it

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