function count(start, end) { console.log(start) var timer = setInterval(() => { if (start < end) { start ++ console.log(start) } else { clearInterval(timer) } }, 100) return { cancel: function() { clearInterval(timer) } } }