Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 10 months ago

Age Calculator App

Chrision Wynaar•340
@Clipzorama
A solution to the Age calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

Im proud that I was able to finish the solution and next time, I might add some additions to the solution.

What challenges did you encounter, and how did you overcome them?

Challenges that I encountered was calculating the age for each user to the currentDate. I did research on Date() since I dont really use it much and was able to figure it out.

What specific areas of your project would you like help with?

If anyone has some time, I like some help on how I handled the errors and what should I do to fix them completely. (95% done as anticipated)

    // For all errors
    resetErrors();
    const daysInMonth = getMonthsFromDays(yearInput, monthInput - 1);

     // Check if all fields are empty or invalid
     if (!dayInput && !monthInput && !yearInput) {
        showError("All fields are required", [errorD, errorM, errorY], [days, months, years]);
        return;
    }

    if (monthInput < 1 || monthInput > 12 &&
        dayInput < 1 || dayInput > daysInMonth &&
        yearInput > currentDate.getFullYear()
    ) {
        showError("Must be a valid month", [errorM], [months]);
        showError("Must be in the past", [errorY], [years]);
        showError("Must be a valid day", [errorD], [days]);
        return;
    }

    if (monthInput < 1 || monthInput > 12) {
        showError("Must be a valid month", [errorM], [months, years, days]);
        return;
    }

    if (dayInput < 1 || dayInput > daysInMonth) {
        showError("Must be a valid day", [errorD], [days, months, years]);
        return;
    }

    if (yearInput > currentDate.getFullYear()) {
        showError("Must be in the past", [errorY], [years, months, days]);
        return;
    }

function showError(message, errorElements, inputElements) {
    inputElements.forEach(element => element.classList.add("error"));
    inputTitle.forEach(element => element.classList.add("error-color"));
    errorElements.forEach(errorElement => {
        errorElement.classList.remove("hidden");
        errorElement.textContent = message;
    });
    days.value = "";
    months.value = "";
    years.value = "";
}

// Function to reset error messages and input styles
function resetErrors() {
    [errorD, errorM, errorY].forEach(errorElement => errorElement.classList.add("hidden"));
    [days, months, years].forEach(input => input.classList.remove("error"));
    inputTitle.forEach(element => element.classList.remove("error-color"));
}



Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Chrision Wynaar's solution.

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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License