Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

age calculator

@katrine9176

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hello everyone!

Long time no see! After 2 months break (exams) I'm back even tho I was thinking about qutting it because of the long not-studying/not-repeating.

Here is my solution of age calculator app. I encountered many seemingly basic problems (😭) so I will appreciate feedbacks :)

  • Why calculateBtn.addEventListener('click', isDateValid(daysAgo.value, monthsAgo.value)) doesn't work? Function runs before clicking button.
  • The way of counting days is messed up in some cases and once works once not.
  • Validation worked but now I really don't know what I missed - it doesn't work at all.

Have a great day and happy coding!

Community feedback

@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

0

@katrine9176

Posted

@bramizdev thankss

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord