From bdb5b0f0a0bbdc2fe4be04492b438d6b4d8a32eb Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Fri, 21 Jan 2022 20:15:50 -0300 Subject: [PATCH] replay counter function added --- index.html | 7 +++++++ script.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 8e33248..7f76c59 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,13 @@ +
+ + + + + +
diff --git a/script.js b/script.js index d38f42a..eaf83af 100644 --- a/script.js +++ b/script.js @@ -1,10 +1,14 @@ -function counter(number, seconds) { +function counter(number, seconds, e) { + e.preventDefault() + seconds = seconds * 1000 const counterElement = document.getElementById('counter-element') let counterNumber = 0 counterElement.innerText = counterNumber + + const button = document.getElementById("form-button") function setTimeOutFunction() { @@ -13,15 +17,35 @@ function counter(number, seconds) { if (counterNumber <= number) { + button.disabled = true setTimeout(setTimeOutFunction, seconds) } else { + button.disabled = false clearTimeout(setTimeOutFunction) + return true } } setTimeout(setTimeOutFunction, seconds) } -window.onload = () => counter(45, 0.1) \ No newline at end of file +window.onload = () => { + + const button = document.getElementById("form-button") + const counterElement = document.getElementById('counter-element') + + counterElement.innerText = 0 + + const buttonFunction = (e) => { + + const formElement = document.getElementById('form') + const thingToCount = formElement.children[1].value + const seconds = formElement.children[3].value + + counter(thingToCount, seconds, e) + } + + button.addEventListener("click", buttonFunction) +} \ No newline at end of file