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