@bramizdev
Posted
Your JS function is not working as expected because you are calling isDateValid()
immediately and passing its return value as the event listener callback.
A quick solution would be using an anonymous function as the event listener callback:
calculateBtn.addEventListener('click', ()=>isDateValid(daysAgo.value, monthsAgo.value))
By the way your approach would have worked if isDateValid
wouldn't need any arguments calculateBtn.addEventListener('click', isDateValid)
, When you use parentheses ()
after a function name, it immediately executes the function. That's why you need an anonymous function.
Marked as helpful
@katrine9176
Posted
@bramizdev thankss