mirror of
https://github.com/FranP-code/Vanilla-Javascript-Counter.git
synced 2025-10-12 23:52:56 +00:00
Styles added
This commit is contained in:
25
script.js
25
script.js
@@ -1,4 +1,4 @@
|
||||
function counter(number, seconds, e) {
|
||||
function counter(number, seconds, e, button) {
|
||||
|
||||
e.preventDefault()
|
||||
|
||||
@@ -6,16 +6,15 @@ function counter(number, seconds, e) {
|
||||
|
||||
const counterElement = document.getElementById('counter-element')
|
||||
let counterNumber = 0
|
||||
counterElement.innerText = counterNumber
|
||||
|
||||
const button = document.getElementById("form-button")
|
||||
|
||||
button.disabled = true
|
||||
|
||||
function setTimeOutFunction() {
|
||||
|
||||
counterElement.innerText = counterNumber
|
||||
counterNumber++
|
||||
counterElement.innerText = counterNumber
|
||||
|
||||
if (counterNumber <= number) {
|
||||
if (counterNumber < number) {
|
||||
|
||||
button.disabled = true
|
||||
setTimeout(setTimeOutFunction, seconds)
|
||||
@@ -37,14 +36,20 @@ window.onload = () => {
|
||||
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
|
||||
const thingToCount = formElement.children[0].children[1].value
|
||||
const seconds = formElement.children[1].children[1].value
|
||||
|
||||
counter(thingToCount, seconds, e)
|
||||
if (!thingToCount || !seconds) {
|
||||
|
||||
alert('Fill all inputs!')
|
||||
return
|
||||
}
|
||||
|
||||
counter(thingToCount, seconds, e, button)
|
||||
}
|
||||
|
||||
button.addEventListener("click", buttonFunction)
|
||||
|
||||
Reference in New Issue
Block a user