Problem with timer (function)

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

But i have a problem with my function

function timeIt(){
  $('#timer').html(convert(timeleft - 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.

Maybe something like:

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

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(){
}, 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.

Do you have a new fiddle version to look at?

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.

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.

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: