**Hello Everyone I have problem with function countdown time have format mm:ss, When count < -10 the count not return same format 0m:0s AND when mm > -10 , mm not return -10
Thanks in advance for any replies and help.
**
The problem is in your getTimeRemaining function:
if (seconds < 0 && seconds <= -10) {
seconds = "0" + seconds;
minutes = "-" + minutes;
}
First, you’ll have to change the condition to seconds >= -10
,
second, when that condition is true, the value of seconds
is negative, so you’re essentially assigning seconds
with "0" + -5
, which (due to type coercion - the first value is a string so the second one will be converted to a string, too) evaluates to 0-5
. The solution is to make seconds
positive again:
if (seconds < 0 && seconds >= -10) {
seconds = "0" + -seconds;
}
Also, setting the minutes in that if condition makes no sense, because it’s only true during the first 10 seconds after the countdown went below zero.
1 Like