AgeCalculatorApplication

screenshot of age calculator app

Project overview

The project is a simple web application developed as a part of the Frontend Mentor Challenges, where the design is provided. It asks the user to input their date of birth in the day, month, and year format. The user interface includes a form with three separate input fields and a submit button. After submission, the application calculates the user's age in years, months, and days and presents the results underneath the form. Additionally, the application displays error messages if any of the input fields are blank or if the entered date is invalid.

Technologies used

Key features

Users are prompted to input their date of birth using three separate fields for the day, month, and year. age calculator app mobile view If any field is left blank or contains an invalid value, an error message is displayed, and the age calculation is not performed. age calculator app empty fields error age calculator app invalid inputs error age calculator app error message and style for whole form Upon entering valid values and clicking the 'Submit' button, the application calculates the user's age in years, months, and days and displays the results underneath the form. age calculator app valid inputs and age calculation The application restricts non-digit characters from being entered and dynamically displays and removes error messages based on user input. Additionally, the application employs responsive design principles, ensuring an optimal user experience across various screen sizes and devices.

Challenges and solutions

During the development process, I encountered several challenges, including validating the user input, restricting non-digit characters in the input fields, dynamically handling error messages, accurately calculating the user's age, and animating numbers.

  1. To ensure the input for day, month, and year is valid, I implemented various validation functions in JavaScript. These functions check if the input fields are empty or if the entered date is valid, and display appropriate error messages if necessary. This approach ensures the age calculation is not performed unless the input is valid.
  2. To ensure only valid numerical inputs were entered by the user, I utilized JavaScript to listen for keydown events and prevent the entry of non-digit characters. This approach ensures that only valid numerical inputs are accepted.
  3. I designed the application to dynamically display and remove error messages based on user input. It was essential to clear the error messages and associated input and label styles when the user started typing in an input field or when the submit button was clicked. This enhancement to the user experience was managed using JavaScript.
  4. Once the input validation was successfully passed, the application calculates the user's age in years, months, and days from the entered birthdate to the current date. The results are then displayed in appropriate spans, ensuring accurate age calculation and presentation.
  5. To make the application more engaging, I implemented a function in JavaScript to manage the animation of the numbers from 0 to their final value when displaying the calculated age. This contributed to a more engaging user experience.

Learning outcomes

Through this project, I have deepened my understanding and sharpened various existing skills:

Project source code and website URL: