
Design comparison
SolutionDesign
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"));
}
Community feedback
Please log in to post a comment
Log in with GitHubJoin 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