Reset values in timer

Hi everyone.

I have got a problem with my timer. I am almost at the end of my task, but one thing is not working properly - after clicking RESET button clock stopped, but the values are not going back to zero.

My code is below:

https://codepen.io/Krzysiek1981/pen/MWgyQYO

Thanks.

@KrzysztofSobota Not sure what this app is supposed to do when you click on PLAY or RESET. Neither seem to do anything. Maybe you should walk us through how you are supposed to use to see the issue you are having.

Also, the expected use of the ternary operator would be:

// 00-09 or 10-59 numbers range      
timerParam.innerHTML = timing < 10 ? `${1 % 1}${timing}` : `${timing}`;

instead of what you did (below):

// 00-09 or 10-59 numbers range      
timing < 10 ? timerParam.innerHTML = `${1 % 1}${timing}`
  : timerParam.innerHTML = `${timing}`;

Actually, I am not even sure why you have ${1 % 1} here. The result would be 0, so why not just write it like:

timerParam.innerHTML = (timing < 10 ? '0' : '') + timing;

Not sure what this app is supposed to do when you click on PLAY or RESET. Neither seem to do anything. Maybe you should walk us through how you are supposed to use to see the issue you are having.

If you need all my JS code (300 lines), but OK maybe more info.
I miss clear option in this timer in the game.

Actually, I am not even sure why you have ${1 % 1} here

Because inside the timer (00:00:00) I need number not string. ‘0’ give string, expression 1%1 is always number. Maybe I am wrong.

The one more problem is when I put console.log - when time range is 10-59, I take “010”, “011” etc., not “10”, “11”…

This is not a number. It is a string formatted to be time, so ‘0’ is what you need. Either way, 1 % 1 is still the number 0, so if you want the number 0, just use the 0 instead of 1 % 1.

OK, but how to put every timer values to zero after click RESET button (which only stop time, without resetting it)? Make new function/value?

I still don’t understand what your existing code is trying to do. The time never changes at this point. Clicking PLAY does nothing from what I can tell, so there is nothing to reset.

This will be a clock for the game. Time is going up from 00:00:00 by 1 second and timer could be clear in any moment by a user (click RESET button).

At this moment my timer can be only stopped - I need stop and clean all value to 00:00:00.

For example: 00:00:00 (click start) -> 00:02:13 (click reset = stop + clean by some function or value) -> 00:00:00

I know that clicking RESET button don’t reset the timer (as it should), but there could be more than one event “connected” into mouse click, right?

Probably you need all my code (with text explaining game rules):

https://codepen.io/Krzysiek1981/pen/qzbvvJ?editors=0110