abobykin / bingo

Bingo game for the website about productivity
0 stars 0 forks source link

How do I make the timer to add "0" to the seconds? #2

Closed Reasonab1e closed 2 months ago

Reasonab1e commented 3 months ago

bandicam 2024-06-27 14-17-45-005

abobykin commented 3 months ago

In this line ${minutes}:${seconds} you will need to check the string of seconds for length with a condition (exactly as a string, for this you can use the toString() or String() methods, the reference book helps), and if the length is more than less than two characters (the case as in your screenshot), you need to add another zero ("0") to the string (there after the colon), and if the condition is false (in the else part of the type) do not add "0".

HINT: All this can be written in the same line, using the ternary operator - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator)

@Reasonab1e