SarthakKeshari / calc_for_everything

This repository aims to provide Calculators for educational, professional, scientific, health and well-being and other purposes.
https://calc-for-everything-psi.vercel.app
MIT License
113 stars 103 forks source link

Added Sleep Calculator #509

Closed roniragilimankhoirul closed 10 months ago

roniragilimankhoirul commented 10 months ago

Issue Id you have worked upon -

471

Briefly explain your program logic -

  1. Validation: It checks if the age is empty or not a positive integer. If it's not a valid input, it sets the error state and returns the error message "Please enter a valid age (use numbers only)."
  2. Conversion: If the age input is valid, it calculates ageInMonths based on the selected ageUnit (months or years). If ageUnit is in months, it uses the age directly; otherwise, it multiplies the age by 12 to convert it to months.
  3. Recommendation Selection: It uses a series of switch statements to determine the appropriate sleep recommendation based on the ageInMonths or age and ageUnit. If a valid recommendation is found, it sets the result variable to that recommendation. It based on an article from Centers for Disease Control and Prevention
  4. No Recommendation: If no valid recommendation is found, it keeps the result variable empty.
  5. Result Display: Finally, it checks if result is not empty, and if so, it returns the recommendation. If result is empty, it returns the message "Age not within the specified range for this group."

Screenshots(Attach 2 screenshots of your own input and output) -

image Screenshot_20231025_233513


By raising this PR I affirm that -

SarthakKeshari commented 10 months ago

Congratulations πŸŽ‰ @roniragilimankhoirul on your contribution. Thanks for adding value to this repository. 😊

Let's celebrate this fest πŸ˜ƒ by providing more developers πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’» an opportunity to contribute. Help us make this repository reach far and more by sharing this to your friends and colleagues.

Your efforts can make difference.

SarthakKeshari commented 10 months ago

Hey πŸ‘‹, may you also encourage us by clicking the star icon on the repository main page. ⭐

image

SarthakKeshari commented 10 months ago

@roniragilimankhoirul, Well explained logic. Adding admin-appreciation points for the same. πŸ‘πŸ‘