printNumbers(1, 5);
function printNumbers(from, to) {
let current = from;
let timerId = setTimeout( function go() {
console.log(current);
if (current == to) clearTimeout(timerId);
current++;
console.log(`current: ${current}`);
setTimeout(go, 1000);
}, 1000 )
}
printNumbers(1, 5);
function printNumbers(from, to) {
let current = from;
let timerId = setTimeout(function go() {
timerId = setTimeout(go, 1000);
console.log(`current: ${current}`);
if (current === to) {
clearTimeout(timerId);
}
current++;
}, 1000);
}