Problem with timer (function)

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.

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

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.

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:

1 Like

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

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: