I'm making a Chronometer and i don't understand why when i use a function with parameters it doesn't work but when I write the entire function code replacing the values, it works perfectly, I'm using TypeScript by the way
function countHundrethsOrSeconds(
countedTime: number,
timeChange: number,
timeGrouping: number,
timeShower: string,
) {
countedTime += timeChange;
if (countedTime === timeGrouping) {
countedTime = 0;
};
if (countedTime.toString().length === 1) {
chronoAndTimer[timeShower as keyof typeof chronoAndTimer].textContent = '0' + countedTime.toString();
}
else {
chronoAndTimer[timeShower as keyof typeof chronoAndTimer].textContent = countedTime.toString();
};
};
//some code
secondsInterval = setInterval((): void => {
countHundrethsOrSeconds(seconds, 1, 60, 'secondsShower');
}, 1000);
//doesn't work
secondsInterval = setInterval((): void => {
seconds += 1;
if (seconds === 60) {
seconds = 0;
};
if (seconds.toString().length === 1) {
chronoAndTimer['secondsShower'].textContent = '0' + countedTime.toString();
}
else {
chronoAndTimer['secondsShower'].textContent = countedTime.toString();
}, 1000);
//works but I'm capricious and I want to save lines
The interval doesn't work, I also used a timeOut and it works so I don't know what am I missing.