Stuck on Pomodoro Clock assignment

Stuck on Pomodoro Clock assignment
0

#1

Got stuck on Pomodoro Clock assignment. I created two functions for session and break. Break function is suppose to be invoked, when session time will run out, but instead my clock starts counting negative values. And starts when page is loaded instead of on a click event. https://codepen.io/Anastasyya/full/GmgbOZ/

       $(document).ready(function(){
         function showTime(time) {
               var min = Math.floor(time/60);
               var sec = Math.round(time%60);
               if (sec < 10) {
                    sec = '0' + sec
               }
               var timeString = min+':'+sec
               $('#pomodoro_button_text').text(timeString)
          }

         var sessionTime = 15;
         var breakTime = 5;
         $( ".pomodoro_button" ).click(sessionTimer());

          function sessionTimer() {
             if(sessionTime >= 0){
                 return setInterval(function() {
                    sessionTime--;
                    showTime(sessionTime);
                 }, 1000);
                }
             else {
                console.log("work done");
                  breakTimer();
                }
           }

         function breakTimer() {
             if(breakTime >= 0){
                return setInterval(function() {
                    breakTime--;
                    showTime(breakTime);
                  }, 1000);
               }

          else {
             sessionTimer();
         }
        }

        });

#2

You don’t check sessionTime in your loop. You should check sessionTime in the setInterval function. [quote=“Anastasyya, post:1, topic:106213”]
And starts when page is loaded instead of on a click event.
[/quote]

That is because you use parentheses after the function name. sessionTimer is the function, but by using parentheses (sessionTimer()), you call the function directly.


#3

Thank you, very much! That fixed the problems