mirror of
https://github.com/FranP-code/Vanilla-Javascript-Counter.git
synced 2025-10-12 23:52:56 +00:00
main script done
This commit is contained in:
27
script.js
27
script.js
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user