The following function naturally enters the same loop over and over again. What I want to do is start counting down from 25 seconds, when it's finished, start counting down from 10 seconds, then go back to 25 seconds. But because of the condition I wrote in the else part, it always counts backwards from 10 seconds. How can I fix this?
        var interval = 25000;
        var interval1 = 10000;
        function millisToMinutesAndSeconds(millis) {
            var seconds = ((millis % 60000) / 1000).toFixed(0);
            return (seconds < 10 ? "0" : "") + seconds;
        }
        function tensecond() {
            localStorage.endTime = +new Date() + interval1;
        }
        function reset() {
            localStorage.endTime = +new Date() + interval;
        }
        setInterval(function () {
            var remaining = localStorage.endTime - new Date();
            if (remaining >= 0) {
                document.getElementById("timer").innerText =
                    millisToMinutesAndSeconds(remaining);
            } else {
                tensecond();
            }
        }, 100);
 
     
     
    