Problem with timer (function)

Problem with timer (function)
0

#1

So I’m working to create a simple Pomodoro timer and i created this:
JsFiddle

But i have a problem with my function

function timeIt(){
  $('#timer').html(convert(timeleft - counter));
  counter++;

}

I cannot asign for it a var inside a function something like function timeIt(someVar)…
beacuse whole line of

var x = setInterval(timeIt, 1000);

stops working in case of changing it to for example:

var x = setInterval(timeIt(40), 1000);

Also i want to add it to onClick button event but this is a secondart question.


#2

Maybe something like:

var x = setInterval(function() {
  timeIt(40);
}, 1000);

#3

Yeah! It works, thanks a lot! :slight_smile:


#4

I have one more problem. I cannot stop ticking previous instances of timer when another button is clicked. For example if user click pomodoro button and then short break button it just breaks and shows both pomodoro timer ticker and short break ticker. I created a function:

function pomodoro(x){
   s = setInterval(function(){
  timeIt(x);
}, 1000);
}

to have it run from button onClick event. Then i think i cannot access it. I tried with some booleans if executed but this doesn’t seems to work because i don’t really know where to put it.


#5

Do you have a new fiddle version to look at?


#6

Actually I managed to deal with this! :smiley:
Here’s codepen because jsfiddle have some problems CODEPEN

Main problem was to put clearInterval in a good place.
I have to deal with display and everything will be ok :slight_smile:


#7

As usually as a thank you and showing how much you helped me i throw final version of my pomodoro timer :slight_smile: Pomodoro.


#8

It is a neat app. You may or may not know this, but technically your Pomodoro Clock project does not meet all of the user story requirements. Your app does not meet the following user story requirement:

I can customize the length of each pomodoro.

You have set short and long breaks, but a user can not create their own break time lengths. Also, the idea of a pomodoro clock is that you can set both the work time and the break and only have to click a start button. The work time and break times would fire automatically without any user intervention once they are set.


#9

Codepen
So after few hours (actually about 2!) I’ve done it. I added custom pomodoro loop including pomodoro timer + ring when pomodoro ends + break timer. Unfortunatelly I’m too lazy to include ring to codepen but belive me it works.
Also With submit button u can assign your break and work time. It’s assigned for both break button’s so I will think about additional “Custom break” button. Thank you for your advices and I’m waiting for more :smiley: