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 using JavaScript, CSS Grid and flexbox

@aboobaqr

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


If you have the time to check please let me know where and how I can improve, I wrote over 230 lines of JavaScript. 😩 I really think it's too much for this project.

Community feedback

JJacobPR 240

@JJacobPR

Posted

Hey,

as you are probably beginner, don't worry that your code is that long, you will improve as you practice. But here are 2 major tips for your programming habits not only js but overall.

  1. Separation of concerns Your click function is too long. All of your comment should be functions. It will make code more readable and easier to change
  2. Hard coded values If you can, don't use hard coded values. In this code, firstly it is longer then needed and it doesn't cover case when February has 29 days.
 if (monthInput.value == 2 && dayInput.value > 28)

When you can, try to use other methods. Here recommended are inbuilt Date functions that you should explore. This is my example of validating day by inbuilt functions:

  const dayValidator = () => {
    //Checking if day is okay in current year case 
    if (year === currentYear && month === new Date().getMonth() + 1 && day > new Date().getDate()) return false;

    //Checking if day is okay based on particular month length
    if (day >= 1 && day <= new Date(year, month, 0).getDate()) return true;
    else return false;
  };

Marked as helpful

0

JJacobPR 240

@JJacobPR

Posted

@aboobaqr Of course in the first point I meant comment sections :)

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