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
Jochem
Jochemβ€’2y ago
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
Sste
SsteOPβ€’2y ago
Wow, sorry for my mistake. Could you help me with this question please?
Jochem
Jochemβ€’2y ago
I'll try to take a look later
Chris Bolson
Chris Bolsonβ€’2y ago
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.
Sste
SsteOPβ€’2y ago
So I need to create a new property in the object to 25 minutes?
Chris Bolson
Chris Bolsonβ€’2y ago
Why are you updating the startTime value?
Sste
SsteOPβ€’2y ago
Because of the short and long break
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Chris Bolson
Chris Bolsonβ€’2y ago
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.
Sste
SsteOPβ€’2y ago
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?
Chris Bolson
Chris Bolsonβ€’2y ago
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)
Sste
SsteOPβ€’2y ago
Yes, I remove and it worked like you said 😊. Now, I need to solve the reset button
Chris Bolson
Chris Bolsonβ€’2y ago
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.
Sste
SsteOPβ€’2y ago
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)?
Chris Bolson
Chris Bolsonβ€’2y ago
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.
Sste
SsteOPβ€’2y ago
If I use conditional statements in the reset button for these values?
Chris Bolson
Chris Bolsonβ€’2y ago
const myPomodoro = {
currentTime: 0,
startTime: 1500, //1500 seconds = 25min
shortBreakTime: 300, //300 seconds = 5mim
longBreakTime: 900, //900 seconds = 15min
currentType: 'normal'
}
const myPomodoro = {
currentTime: 0,
startTime: 1500, //1500 seconds = 25min
shortBreakTime: 300, //300 seconds = 5mim
longBreakTime: 900, //900 seconds = 15min
currentType: 'normal'
}
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 type
Sste
SsteOPβ€’2y ago
Thanks so much, ChrisπŸ‘. I will give this a try It didn't work. Just stoped the clock, but didn't reset
Chris Bolson
Chris Bolsonβ€’2y ago
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.
Sste
SsteOPβ€’2y ago
Thanks πŸ‘
Chris Bolson
Chris Bolsonβ€’2y ago
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
Want results from more Discord servers?
Add your server