Skip to content

dhruv-bamal/Modern-Age-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🎂 Age Calculator

A sophisticated and elegant web application that calculates your exact age in years, months, and days. Built with vanilla HTML, CSS, and JavaScript, featuring a premium design with smooth animations, advanced calculations, and comprehensive life statistics.

✨ Features

  • Precise Age Calculation: Calculates exact age down to the day with accurate month and day handling
  • Comprehensive Life Statistics:
    • Total days lived
    • Total hours lived
    • Days until your next birthday
    • Smart birthday detection (shows "🎂 Today!" on birthday)
  • Beautiful Animations: Smooth transitions with pop effects on result updates and elegant fade-in animations
  • Input Validation: Prevents future dates and validates all user input
  • Keyboard Support: Press Enter to calculate after selecting a date
  • Responsive Design: Optimized for both desktop and mobile devices with adaptive layouts
  • Premium UI: Warm, sophisticated color palette with professional typography and subtle noise texture
  • Number Formatting: Indian locale formatting for better readability

🛠️ Technologies Used

  • HTML5: Semantic markup with modern structure
  • CSS3: Advanced styling with:
    • CSS custom properties (variables) for cohesive theming
    • Flexible box layout and CSS Grid
    • Smooth animations and transitions
    • Box shadows and border radius for depth
  • JavaScript (Vanilla): Pure JS for complex date calculations and DOM manipulation

📦 Project Structure

Age-Calculator/
├── index.html      # Main HTML file with semantic structure
├── style.css       # Premium styling with CSS variables and animations
├── script.js       # Advanced date calculation logic and interactivity
└── README.md       # Project documentation

🚀 Getting Started

Prerequisites

  • Any modern web browser (Chrome 90+, Firefox 88+, Safari 14+, Edge 90+)

Installation & Usage

  1. Open in Browser

    • Simply open index.html in your preferred web browser
  2. Optional: Use Local Server

    # Python 3
    python -m http.server 8000
    
    # Python 2
    python -m SimpleHTTPServer 8000
    
    # Node.js (with http-server)
    npx http-server
  3. Calculate Your Age

    • Select your date of birth from the date picker
    • Click "Calculate Age" button or press Enter
    • View your detailed age breakdown and life statistics

💡 How It Works

Age Calculation Algorithm

The application implements a sophisticated date calculation system:

  1. Base Calculation: Compares birth date with today's date to get initial year, month, and day differences
  2. Edge Case Handling:
    • If remaining days are negative, borrows 1 month and adds the previous month's days
    • If remaining months are negative, borrows 1 year and adds 12 months
  3. Total Days: Calculates precise total days lived using millisecond-accurate date math
  4. Next Birthday: Intelligently determines days until next birthday, handling year rollovers

Advanced Features

  • Animated Transitions: Values smoothly animate from current to target numbers over 600ms with cubic easing
  • Pop Animation: Result values briefly scale up (108%) when updating for visual feedback
  • Staggered Display: Extra statistics animate in sequence (150ms delay) for elegant reveal
  • Date Validation:
    • Prevents selection of future dates
    • Requires valid date input
    • Shows clear error messages

🎨 Design System

Color Palette

  • Primary Background: Warm beige (#f2ede6)
  • Surface: Off-white (#faf7f3)
  • Accent: Elegant brown (#b5713a)
  • Accent Light: Warm tan (#d4935c) for hover states
  • Text Primary: Deep brown (#231f1a)
  • Text Secondary: Muted taupe (#7a6e63)

Typography

  • Display Font: Cormorant Garamond (serif) - elegant, sophisticated
  • Body Font: DM Sans (sans-serif) - clean, readable
  • Font Weights: 300 (light), 400 (regular), 500 (medium), 600 (bold)

Visual Elements

  • Border Radius: 20px (cards), 12px (inputs/buttons) for smooth aesthetic
  • Shadows: Multi-level shadow system for depth and hierarchy
  • Noise Texture: Subtle SVG-based noise overlay for premium feel
  • Button Effects: Smooth color transitions, shadow depth changes, and arrow animations on hover

🐛 Error Handling

The application gracefully handles various scenarios:

  • No Date Selected: "Please select your date of birth."
  • Future Date: "Date of birth cannot be in the future."
  • Valid Date: Displays comprehensive age breakdown with animations
  • Birthday Today: Shows special emoji message "🎂 Today!"

📱 Responsive Design

  • Desktop: Full-width card (max 520px) with optimal spacing
  • Tablet: Adaptive layout maintains readability
  • Mobile (≤420px):
    • Single-column stat layout
    • Adjusted padding for touch targets
    • Horizontal stat arrangement for compact display

📂 Key Functions

Function Purpose
calculateAge(dob) Computes years, months, days from birth date
getTotalDays(dob) Calculates total days lived
getDaysToNextBirthday(dob) Computes days until next birthday
animateValue(el, target) Smoothly animates number changes
handleCalculate() Main calculation handler with validation
formatNumber(n) Formats numbers using Indian locale

🎯 User Experience Features

  • Instant Feedback: Results appear immediately with smooth animations
  • Keyboard Navigation: Full support for Enter key
  • Clear Guidance: Input hints and labels for clarity
  • Visual Hierarchy: Important information emphasized with larger, accent-colored text
  • Loading States: Disabled state implicitly handled through validation
  • Accessibility: Semantic HTML with proper labels and ARIA considerations

🚧 Future Enhancement Ideas

  • Add timezone support for global accuracy
  • localStorage for calculation history
  • Dark mode theme toggle
  • Export results as PDF or image
  • Age comparison with other dates
  • Horoscope or zodiac sign integration
  • Share results on social media
  • Multiple date format support

📄 License

Free to use for personal or commercial projects.

🎉 About

"Time is the most valuable thing you own." — Designed to help you appreciate every moment of your life.

  • Add animations to age display update
  • Dark mode toggle
  • Birthday countdown feature

📄 License

This project is open source and available under the MIT License.

🤝 Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🙏 Acknowledgments

  • This project was developed with AI-assisted coding
  • Inspired by the need for a quick and accurate age calculator
  • Built as a learning project in vanilla JavaScript

📧 Contact

Feel free to reach out with suggestions, feedback, or collaboration opportunities!


Made with ❤️ using Vanilla JS

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors