mirror of
https://github.com/FranP-code/Vanilla-Javascript-Counter.git
synced 2025-10-12 23:52:56 +00:00
27 lines
615 B
JavaScript
27 lines
615 B
JavaScript
function counter(number, seconds) {
|
|
|
|
seconds = seconds * 1000
|
|
|
|
const counterElement = document.getElementById('counter-element')
|
|
let counterNumber = 0
|
|
counterElement.innerText = counterNumber
|
|
|
|
function setTimeOutFunction() {
|
|
|
|
counterElement.innerText = counterNumber
|
|
counterNumber++
|
|
|
|
if (counterNumber <= number) {
|
|
|
|
setTimeout(setTimeOutFunction, seconds)
|
|
|
|
} else {
|
|
|
|
clearTimeout(setTimeOutFunction)
|
|
}
|
|
}
|
|
|
|
setTimeout(setTimeOutFunction, seconds)
|
|
}
|
|
|
|
window.onload = () => counter(45, 0.1) |