Problem with a button
I am having problem with the "pomodoro" button. The standard of pomodoro is 25 minutes, but when I click in the 'short break' button or in the 'long break' button and then I try to come back to the pomodoro button which is 25 minutes and simply don't work. What is the problem and how can I solve it?
https://codepen.io/Sstephanyyy/pen/MWPmaNo
21 Replies
When you get an answer please don't delete the thread like you did the last one. Someone else might still be able to learn from your question. You can just add the solved tag
Wow, sorry for my mistake.
Could you help me with this question please?
I'll try to take a look later
When you click on the short and long break buttons you are updating your pomdoro startTime to be that button start time (shortBreakTime or longBreakTime).
So, when you next click on the pomadoro button it is resetting to that modified start time and not is't inital value.
So I need to create a new property in the object to 25 minutes?
Why are you updating the startTime value?
Because of the short and long break
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Ideally the 3 different start times would immutable constants, ie variables that can't be changed.
I am not clear as to why you need these lines:
myPomodoro.startTime = myPomodoro.shortBreakTime;
and
myPomodoro.startTime = myPomodoro.longBreakTime;
If I remove them the buttons work (more or less) as I would expect.Actually I realized it's because when I click in the reset button, If I don't update the start time value, it will continue 25 minutes. Even if it is in the short break (5min) or in the long break (25min)
How could I solve in another way so that pomodoro button works perfectly?
I am not 100% clear as to what you expect to happen when you click on the pomodoro button.
If you remove those two lines that I mentiond, clicking on the pomodoro button resets the timer to 25:00
(Sorry if I am missing the point, I am not familiar with the pomodoro concept, I am just reading up on it now)
Ah, OK, so the issue is with the reset button rather than the pomodoro button. Maybe you should look at what value it is using to reset to (I haven't looked at that part of your code yet)
Yes, I remove and it worked like you said 😊. Now, I need to solve the reset button
you could create a variable that holds the current counter type (pomodoro, short or long) and use that type to define which reset value to use.
Sorry me to, because sometimes I don't know how to ask my questions in a clearly way
So I need to create multiple reset button to call each variable (pomodoro, short and long)?
I would keep the single button but add a new variable which would be modified as you click on each button. In the reset function you then use this new variable value (eg "normal", "short" or "long") to decide which reset time value to use.
If I use conditional statements in the reset button for these values?
reset button:
```
...
const buttonType = myPomodoro.currentType;
if(buttonType == "short"){
myPomodoro.currentTime = myPomodoro.shortBreakTime;
} else if (buttonType == "long"){
myPomodoro.currentTime = myPomodoro.longBreakTime;
} else {
myPomodoro.currentTime = myPomodoro.startTime;
}
...```
modified to simplify the code by defining a new variable for the button type
then in each button:
myPomodoro.currentType = "normal";`
changing the value according to the button typeThanks so much, Chris👍. I will give this a try
It didn't work. Just stoped the clock, but didn't reset
There was a small typo in my original message, it may have been that.
I’ll make a fork of your codepen later and see if I can see what is happening.
Thanks 👍
Probably just more typos before - I really shouldn't use the iPhone for writing code (that's my excuse anyway).
Here is my fork of your codepen with the add variable control for the active button.
https://codepen.io/cbolson/pen/bGmWjbO?editors=0010