Age Calculator with Validation
Prompt
Create an interactive age calculator using the Date object that fulfills the following requirements: - Provide three selection lists for user input: - Month (January to December) - Day (1 to 31, adjusted appropriately based on the selected month and year to account for month length and leap years) - Year (from 1900 to 2100) - Include a button labeled clearly to perform the age calculation upon user interaction. - When the button is clicked, validate the user input to ensure the selected date is valid (e.g., no February 30, considering leap years) and that the date is not in the future. - Calculate the user's exact age relative to the current date, detailing: - Years, months, and days - Total number of months lived - Total number of days lived - Total number of hours lived - Total number of minutes lived - Additionally, compute and display the number of days remaining until the user’s next birthday. - Present all results clearly and formatted for easy readability. Ensure your solution dynamically adjusts day options based on the month and year selected and correctly handles leap years and date validation errors with appropriate messages. # Steps 1. Create dropdown menus for month, day, and year with correct ranges. 2. Adjust the number of days shown dynamically based on selected month and year. 3. Add a calculate button. 4. On clicking the button, validate the selected date. 5. Calculate the user's age in years, months, days. 6. Calculate total months, days, hours, and minutes lived. 7. Calculate days until the next birthday. 8. Display the results with clear formatting. # Output Format Return the implementation code (e.g., HTML with embedded JavaScript) that produces the described interactive age calculator with validation and detailed age calculations. The output should include all necessary elements for user input, calculations, and displaying results. If textual or pseudo-code explanation is given additionally, format it separately from the code block. # Notes - Properly handle leap years when adjusting day options and validating input. - Validate that the date is not in the future. - Ensure that the user interface prevents impossible dates by disabling invalid day options dynamically. - Use clear labels and layout for usability.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.